how to get the datetime.date() value from django model?

I have a problem in getting the datetime.date() value in my django... when i trying to get it like this :

>>> s = Booking.objects.values('date_select').distinct('date_select').filter(date_select='2011-12-1')
>>> print s
[{'date_select': datetime.date(2011, 12, 1)}]

it has the column of date_select, i just only want the datetime.date(2011, 12, 1), do anyone have an idea about it? i also try this one but its not working :

>>> s = Booking.objects.values('date_select').distinct('date_select').filter(date_select='2011-12-1')['date_select']
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 153, in __getitem__
    raise TypeError
TypeError
>>> 

thanks...

Answers


you are getting back a list with one element so you need to do this:

s = Booking.objects.values('date_select').distinct('date_select').filter(date_select='2011-12-1')[0]['date_select']

Need Your Help

Boolean Toggle in Nested Form

ruby-on-rails ruby ruby-on-rails-4 boolean nested-resources

I have a Issues Controller and a nested Comments Controller. My Comments form is in my Issues Show View.

how to pass value when popToRoot

iphone ios xcode uinavigationcontroller

will like to know how do i pass value back to the root view controller when i popToRoot.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.