filter Datetimefield

19 views
Skip to first unread message

Rafael Borella

unread,
Dec 21, 2014, 9:04:49 AM12/21/14
to django...@googlegroups.com
Hi,  i'm new in django and python,

I'm trying to create a queryset to filter according to date.

this is my MODEL :  data = models.DateTimeField()

and my VIEW:        def resultado(request, dia, mes, ano):
                           lista_de_balada= Balada.objects.filter(data__year=ano, data__month=mes, data__day=dia)
                           context = {'lista_de_balada':lista_de_balada}
                           return render(request, 'procurar.htm', context)

it presents no errors, but the query is aways empty...    if i take off   __month     and    __day  it works fine.   but i need to filter according to date  not only year.

Sorry for the english, is not my native language.

Vijay Khemlani

unread,
Dec 21, 2014, 11:06:09 AM12/21/14
to django...@googlegroups.com
When you print the SQL query that is executed on the database

print lista_de_balada.query

Does it make sense?

When you see the actual value stored in the database is it stored correctly?

Also remember that the month and day are 1-based (january is 1, february is 2, etc)

Suerte! :D

 

--
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/948e257d-f704-4dd5-8797-750ba253bcec%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Rafael Borella

unread,
Dec 21, 2014, 4:51:53 PM12/21/14
to django...@googlegroups.com

I figured out  what did happen...

i just needed to put midnight on timefield   and it worked

Thks for help!!
Reply all
Reply to author
Forward
Message has been deleted
0 new messages