Sunday, December 21, 2014

Re: filter Datetimefield

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

 

On Sun, Dec 21, 2014 at 11:04 AM, Rafael Borella <rafaelborella2@gmail.com> wrote:
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.

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@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.

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@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/CALn3ei1W3eBcQQk_jmpJy4%2B6EHeW4sQzvEPaFanbi4eUwD1Q5A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment