Entry.objects.filter(pub_date__month=7) doesn't work with Django 1.8

44 views
Skip to first unread message

lxm

unread,
Sep 22, 2015, 10:57:30 AM9/22/15
to Django users
I create a class named Entry,like this:
class Entry(models.Model):
    pub_date = models.DateTimeField()
this data table named Entry have one record:
  • pub_date = '2015-7-14 xx:xx:xx'
then,I excute 'Entry.objects.filter(pub_date__year=2015)' in shell,this will return right result,
but when I excute 'Entry.objects.filter(pub_date__month=7)',this return empty list.

Bill Freeman

unread,
Sep 22, 2015, 1:52:10 PM9/22/15
to django-users
What does the following say?

   Entry.objects.filter(pub_date__year=2015)[0].pub_date.month

If it says 7, then its time to delve into the generated SQL for the month query.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b29a0450-f0c6-421a-be33-770338f5965d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages