Lookup hour on DateTimeField Django -



Lookup hour on DateTimeField Django -

i have model

class item(models.model): inicio = models.datetimefield()

when seek create query:

itens = item.objects.filter(inicio__hour__gte=6)

it returns me:

fielderror unsupported lookup 'hour' datetimefield or bring together on field not permitted.

how can create query?

you need filter using timedelta:

from datetime import datetime, timedelta five_hours_ago = datetime.now() - timedelta(hours=5) items = item.objects.filter(inicio__lt=five_hours_ago)

you can specify exact datetime , subtract 5 hours if don't want 5 hours current datetime.

to best of knowledge, , according documentation, can exact lookup on hour, min or second.

django django-models django-queryset

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -