[Django] #36066: Documentation about the use of Q objects inside of the annotate method would be nice.

5 views
Skip to first unread message

Django

unread,
Jan 5, 2025, 6:31:48 PM1/5/25
to django-...@googlegroups.com
#36066: Documentation about the use of Q objects inside of the annotate method
would be nice.
-------------------------------------+-------------------------------------
Reporter: Laurent Bergeron | Type:
| Uncategorized
Status: new | Component: Database
| layer (models, ORM)
Version: 5.1 | Severity: Normal
Keywords: documentation | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
I needed to annotate something to a queryset and found a solution that
looked like this:
{{{
queryset = MyModel.objects.annotate(
created_less_than_hour_ago=Q(time_of_creation__gt=(now() -
timedelta(hours=1)))
)
}}}

It worked fine and "created_less_than_hour_ago" was set to True if the
object was created less than an hour ago and to False otherwise. I found
another way to achieve this though because I didn't find any documentation
about the use of Q objects inside of the annotate method, so I couldn't
understand why and how it worked.

So, here I am asking for documentation about it.
--
Ticket URL: <https://code.djangoproject.com/ticket/36066>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jan 5, 2025, 6:33:04 PM1/5/25
to django-...@googlegroups.com
#36066: Documentation about the use of Q objects inside of the annotate method
would be nice.
-------------------------------------+-------------------------------------
Reporter: Laurent Bergeron | Owner: (none)
Type: New feature | Status: new
Component: Database layer | Version: 5.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: documentation | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Laurent Bergeron):

* type: Uncategorized => New feature

--
Ticket URL: <https://code.djangoproject.com/ticket/36066#comment:1>
Reply all
Reply to author
Forward
0 new messages