Hi I have a user input form which takes date in 2011-05-12 format. I want to query the results using Q . But my database field is in datetime format something like 2011-05-18 08:36:34. I am giving the query like this
k = Posts.objects.filter(Q(review_email__contains = user), review_time = datetime(date)) where user is some username and date is the form inputvalue
If I execute the above query I am getting below error
Traceback (most recent call last):
File "<console>", line 1, in <module>
TypeError: 'module' object is not callable
Can some one help me in solving this. Thanks in advance
The error comes from not doing
datetime.datetime, but as soon you fix that, you’re going run into incorrect results in your query. When you coerce thedatetime.dateto adatetime.datetimeobject it will be at midnight. Consequently, onlyPostscreated exactly at midnight on that day will match.You should do this instead:
See the queryset reference for more info.
On a side note, you don’t really need to use the
Qobject in this.