@@ -208,7 +208,7 @@ The lookup parameters (``**kwargs``) should be in the format described in
208
208
underlying SQL statement.
209
209
210
210
If you need to execute more complex queries (for example, queries with ``OR`` statements),
211
- you can use :class:`Q objects <django.db.models.Q> ` (``*args``).
211
+ you can use :ref:`q- objects` (``*args``).
212
212
213
213
``exclude()``
214
214
~~~~~~~~~~~~~
@@ -250,16 +250,16 @@ In SQL terms, that evaluates to:
250
250
Note the second example is more restrictive.
251
251
252
252
If you need to execute more complex queries (for example, queries with ``OR`` statements),
253
- you can use :class:`Q objects <django.db.models.Q> ` (``*args``).
253
+ you can use :ref:`q- objects` (``*args``).
254
254
255
255
``annotate()``
256
256
~~~~~~~~~~~~~~
257
257
258
258
.. method:: annotate(*args, **kwargs)
259
259
260
260
Annotates each object in the ``QuerySet`` with the provided list of :doc:`query
261
- expressions </ref/models/expressions>` or :class:`~django.db.models.Q` objects.
262
- Each object can be annotated with:
261
+ expressions </ref/models/expressions>` or :ref:`q- objects`. Each object can be
262
+ annotated with:
263
263
264
264
* a simple value, via ``Value()``;
265
265
* a reference to a field on the model (or any related models), via ``F()``;
@@ -1270,9 +1270,9 @@ database.
1270
1270
:meth:`~django.db.models.fields.related.RelatedManager.create`,
1271
1271
:meth:`~django.db.models.fields.related.RelatedManager.remove`,
1272
1272
:meth:`~django.db.models.fields.related.RelatedManager.clear` or
1273
- :meth:`~django.db.models.fields.related.RelatedManager.set`, on
1274
- :class:`related managers< django.db.models.fields.related.RelatedManager>`,
1275
- any prefetched cache for the relation will be cleared.
1273
+ :meth:`~django.db.models.fields.related.RelatedManager.set`, on a
1274
+ :class:`~ django.db.models.fields.related.RelatedManager`, any prefetched
1275
+ cache for the relation will be cleared.
1276
1276
1277
1277
You can also use the normal join syntax to do related fields of related
1278
1278
fields. Suppose we have an additional model to the example above::
@@ -1426,8 +1426,8 @@ where prefetching with a custom ``QuerySet`` is useful:
1426
1426
1427
1427
* You want to prefetch only a subset of the related objects.
1428
1428
1429
- * You want to use performance optimization techniques like
1430
- :meth:`deferred fields <defer()> `:
1429
+ * You want to use performance optimization techniques like deferring fields,
1430
+ for example, via :meth:`defer` or :meth:`only `:
1431
1431
1432
1432
.. code-block:: pycon
1433
1433
@@ -1790,11 +1790,10 @@ will always be fetched into the resulting queryset.
1790
1790
normalize your models and put the non-loaded data into a separate model
1791
1791
(and database table). If the columns *must* stay in the one table for some
1792
1792
reason, create a model with ``Meta.managed = False`` (see the
1793
- :attr:`managed attribute <django.db.models.Options.managed>` documentation)
1794
- containing just the fields you normally need to load and use that where you
1795
- might otherwise call ``defer()``. This makes your code more explicit to the
1796
- reader, is slightly faster and consumes a little less memory in the Python
1797
- process.
1793
+ :attr:`~django.db.models.Options.managed` documentation) containing just
1794
+ the fields you normally need to load and use that where you might otherwise
1795
+ call ``defer()``. This makes your code more explicit to the reader, is
1796
+ slightly faster and consumes a little less memory in the Python process.
1798
1797
1799
1798
For example, both of these models use the same underlying database table::
1800
1799
@@ -2258,9 +2257,9 @@ found, ``get_or_create()`` returns a tuple of that object and ``False``.
2258
2257
inserted.
2259
2258
2260
2259
You can specify more complex conditions for the retrieved object by chaining
2261
- ``get_or_create()`` with ``filter()`` and using :class:`Q objects
2262
- <django.db.models.Q>`. For example, to retrieve Robert or Bob Marley if either
2263
- exists, and create the latter otherwise::
2260
+ ``get_or_create()`` with ``filter()`` and using :ref:`q- objects`. For example,
2261
+ to retrieve Robert or Bob Marley if either exists, and create the latter
2262
+ otherwise::
2264
2263
2265
2264
from django.db.models import Q
2266
2265
@@ -3923,8 +3922,8 @@ of the return value
3923
3922
``filter``
3924
3923
~~~~~~~~~~
3925
3924
3926
- An optional :class :`Q object <django.db.models.Q >` that's used to filter the
3927
- rows that are aggregated.
3925
+ An optional :ref :`Q object <q-objects >` that's used to filter the rows that
3926
+ are aggregated.
3928
3927
3929
3928
See :ref:`conditional-aggregation` and :ref:`filtering-on-annotations` for
3930
3929
example usage.
@@ -4084,6 +4083,8 @@ Query-related tools
4084
4083
This section provides reference material for query-related tools not documented
4085
4084
elsewhere.
4086
4085
4086
+ .. _q-objects:
4087
+
4087
4088
``Q()`` objects
4088
4089
---------------
4089
4090
@@ -4187,7 +4188,7 @@ overridden by using a custom queryset in a related lookup.
4187
4188
4188
4189
.. attribute:: FilteredRelation.condition
4189
4190
4190
- A :class:`~django.db.models.Q` object to control the filtering.
4191
+ A :ref:`Q object <q-objects>` to control the filtering.
4191
4192
4192
4193
``FilteredRelation`` is used with :meth:`~.QuerySet.annotate()` to create an
4193
4194
``ON`` clause when a ``JOIN`` is performed. It doesn't act on the default
0 commit comments