Reputation: 46979
In ,models i have
class pick:
t1 =models.DateTimeField(auto_now_add=True)
In views.
The date variable is in the format s="2010-01-01"
How o query the for the date now
pick.objects.filter(t1=date(s))
Upvotes: 0
Views: 975
Reputation: 258
datetime.date() expected arguments are datetime.date(year, month, day)
, so creating a date object with s
won't work. But you can use the date string directly in filter like
picks_at_date = pick.objects.filter(t1=s)
or when you try to find anything before or after that date
picks_before_date = pick.objects.filter(t1__lt=s)
or
picks_after_date = pick.objects.filter(t1__gt=s).
Django's "Making queries" Docs at Retrieving specific objects with filters has some good examples on making queries with date fields as well.
Upvotes: 1