浏览代码

Fixed #36066 -- Documented that Q objects can be used directly in annotations.

samruddhiDharankar 3 周之前
父节点
当前提交
9120a19c4e
共有 2 个文件被更改,包括 9 次插入4 次删除
  1. 1 0
      AUTHORS
  2. 8 4
      docs/ref/models/querysets.txt

+ 1 - 0
AUTHORS

@@ -916,6 +916,7 @@ answer newbie questions, and generally made Django that much better:
     Sachin Jat <sanch.jat@gmail.com>
     Sachin Jat <sanch.jat@gmail.com>
     Sage M. Abdullah <https://github.com/laymonage>
     Sage M. Abdullah <https://github.com/laymonage>
     Sam Newman <http://www.magpiebrain.com/>
     Sam Newman <http://www.magpiebrain.com/>
+    Samruddhi Dharankar <sdharank@ics.uci.edu>
     Sander Dijkhuis <sander.dijkhuis@gmail.com>
     Sander Dijkhuis <sander.dijkhuis@gmail.com>
     Sanket Saurav <sanketsaurav@gmail.com>
     Sanket Saurav <sanketsaurav@gmail.com>
     Sanyam Khurana <sanyam.khurana01@gmail.com>
     Sanyam Khurana <sanyam.khurana01@gmail.com>

+ 8 - 4
docs/ref/models/querysets.txt

@@ -258,10 +258,14 @@ you can use :class:`Q objects <django.db.models.Q>` (``*args``).
 .. method:: annotate(*args, **kwargs)
 .. method:: annotate(*args, **kwargs)
 
 
 Annotates each object in the ``QuerySet`` with the provided list of :doc:`query
 Annotates each object in the ``QuerySet`` with the provided list of :doc:`query
-expressions </ref/models/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 </ref/models/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
 Each argument to ``annotate()`` is an annotation that will be added
 to each object in the ``QuerySet`` that is returned.
 to each object in the ``QuerySet`` that is returned.