I ran into what I consider somewhat surprising behavior the other day when 
using the `__date` lookup to compare a datetime to a date in a queryset.

It appears according to these docs that the Queryset will convert the 
datetime value in the DateTimeField to the current timezone before 
comparing.
https://docs.djangoproject.com/en/dev/ref/models/querysets/#date

The reason I found this surprising is that `timezone.now()` always returns 
the time in UTC and in this contrived instance I was wanting to compare 
against UTC "today". I know this contrived example doesn't make sense, but 
the longer answer is I had other models' fields being set to UTC "today" 
using `timezone.now().date()`, and was using those fields' values to 
compare against a DateTimeField. The queryset behavior (I believe) doesn't 
work the way I expected in this context. Maybe this is pointing to UTC 
"today" is the "wrong" way to do it?

Is this queryset behavior due to the way timezone aware inputs in forms 
works? I.E. Naive datetime in form -> made aware in currently active 
timezone -> converted to UTC and stored in database if I understand 
correctly?

Thanks,
-Ryan Causey


-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/46be92f6-aca9-4b32-a0ce-799467f73e30o%40googlegroups.com.

Reply via email to