Kartik Prabhu
Kartik Prabhu

Reputation: 228

queryset filter month returns empty

Edit: So I dropped this and then waited for a few days it started working! Some how the upgrade to 1.6 took a while to 'propagate'! shrugs. Thanks to all who chimed in!

The queryset filter month does not seem to be working correctly. I have a bunch of objects in database with model called Note with field pub_date storing a datetime object. I want to retrieve Note objects by month. So here is a test I did:

>>> from blogengine.models import Note
>>> n = Note.objects.all()[0]
>>> n.pub_date
datetime.datetime(2014, 3, 8, 21, 15, 14, tzinfo=<UTC>)

>>> Note.objects.filter(pub_date__year = 2014)
[<Note: Note object>, <Note: Note object>]

>>> Note.objects.filter(pub_date__month =3)
[]

As you can see the year look up works correctly, giving me the two objects with year=2014, but the month lookup returns nothing even though there is an object with that month as can be seen from the first example object n. This also happens for all other datetime lookups like day or minute.

Python = 2.7.5 Django 1.6.2

Upvotes: 4

Views: 1122

Answers (2)

Jonathan Adelson
Jonathan Adelson

Reputation: 3321

I had a similar problem which turned out to be mysql not loading tz info. See here: https://stackoverflow.com/a/14454465/8092

Upvotes: 1

Kartik Prabhu
Kartik Prabhu

Reputation: 228

So I dropped this and then waited for a few days it started working! Some how the upgrade to 1.6 took a while to 'propagate'! shrugs.

Thanks to all who chimed in!

Upvotes: 0

Related Questions