From 9120a19c4ecb643111b073dd1069e6b410a03c23 Mon Sep 17 00:00:00 2001 From: samruddhiDharankar Date: Sat, 1 Mar 2025 14:53:20 -0800 Subject: [PATCH] Fixed #36066 -- Documented that Q objects can be used directly in annotations. --- AUTHORS | 1 + docs/ref/models/querysets.txt | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/AUTHORS b/AUTHORS index b816c305e5..6fd36510c7 100644 --- a/AUTHORS +++ b/AUTHORS @@ -916,6 +916,7 @@ answer newbie questions, and generally made Django that much better: Sachin Jat Sage M. Abdullah Sam Newman + Samruddhi Dharankar Sander Dijkhuis Sanket Saurav Sanyam Khurana diff --git a/docs/ref/models/querysets.txt b/docs/ref/models/querysets.txt index 06d2086328..f824b3050f 100644 --- a/docs/ref/models/querysets.txt +++ b/docs/ref/models/querysets.txt @@ -258,10 +258,14 @@ you can use :class:`Q objects ` (``*args``). .. method:: annotate(*args, **kwargs) Annotates each object in the ``QuerySet`` with the provided list of :doc:`query -expressions `. An expression may be a simple value, a -reference to a field on the model (or any related models), or an aggregate -expression (averages, sums, etc.) that has been computed over the objects that -are related to the objects in the ``QuerySet``. +expressions ` or :class:`~django.db.models.Q` objects. +Each object can be annotated with: + +* a simple value, via ``Value()``; +* a reference to a field on the model (or any related models), via ``F()``; +* a boolean, via ``Q()``; or +* a result from an aggregate expression (averages, sums, etc.) computed over + the objects that are related to the objects in the ``QuerySet``. Each argument to ``annotate()`` is an annotation that will be added to each object in the ``QuerySet`` that is returned.