Opened 4 years ago
Last modified 4 years ago
#31860 closed Bug
"__date" in F expression not working, have to use Func() — at Version 1
Reported by: | Aleksandr Smechov | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 3.1 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
When filtering a query for two equal datetime fields, and using __date
, the __date
in the F expression remains a timestamp.
For example:
Author.objects.filter( Q(articles__isnull=False) & Q(articles__date_published__date=F("articles__date_edited__date")))
This will return an empty set, as F("articlesdate_editeddate") remains a timestamp. I instead have to revert to using Func.
Author.objects .annotate(date_edited=Func(F("articles__date_edited"), function="DATE")) .filter(Q(articles__isnull=False) & Q(articles__date_published__date=F("date_edited")))
The above works. Not sure if relevant, but in settings I have USE_TZ enabled.
Note:
See TracTickets
for help on using tickets.