Opened 4 years ago
Closed 4 years ago
#31860 closed Bug (duplicate)
"__date" in F expression not working, have to use Func()
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 (both being timestamps), 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("articles__date_edited__date")
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.
Change History (4)
comment:1 by , 4 years ago
Description: | modified (diff) |
---|
comment:2 by , 4 years ago
Description: | modified (diff) |
---|
comment:3 by , 4 years ago
Description: | modified (diff) |
---|
comment:4 by , 4 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
Hi. I believe this is a duplicate of #31639.