diff options
| author | Ryan Heard <ryanwheard@gmail.com> | 2021-07-02 15:09:13 -0500 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-03-04 12:55:37 +0100 |
| commit | c6b4d62fa2c7f73b87f6ae7e8cf1d64ee5312dc5 (patch) | |
| tree | 238bd8c3045c8d4577e09bd913de9748dcd49968 /docs/topics | |
| parent | 795da6306a048b18c0158496b0d49e8e4f197a32 (diff) | |
Fixed #29865 -- Added logical XOR support for Q() and querysets.
Diffstat (limited to 'docs/topics')
| -rw-r--r-- | docs/topics/db/queries.txt | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/docs/topics/db/queries.txt b/docs/topics/db/queries.txt index 9e45f66bb5..8118532513 100644 --- a/docs/topics/db/queries.txt +++ b/docs/topics/db/queries.txt @@ -1111,8 +1111,8 @@ For example, this ``Q`` object encapsulates a single ``LIKE`` query:: from django.db.models import Q Q(question__startswith='What') -``Q`` objects can be combined using the ``&`` and ``|`` operators. When an -operator is used on two ``Q`` objects, it yields a new ``Q`` object. +``Q`` objects can be combined using the ``&``, ``|``, and ``^`` operators. When +an operator is used on two ``Q`` objects, it yields a new ``Q`` object. For example, this statement yields a single ``Q`` object that represents the "OR" of two ``"question__startswith"`` queries:: @@ -1124,9 +1124,10 @@ This is equivalent to the following SQL ``WHERE`` clause:: WHERE question LIKE 'Who%' OR question LIKE 'What%' You can compose statements of arbitrary complexity by combining ``Q`` objects -with the ``&`` and ``|`` operators and use parenthetical grouping. Also, ``Q`` -objects can be negated using the ``~`` operator, allowing for combined lookups -that combine both a normal query and a negated (``NOT``) query:: +with the ``&``, ``|``, and ``^`` operators and use parenthetical grouping. +Also, ``Q`` objects can be negated using the ``~`` operator, allowing for +combined lookups that combine both a normal query and a negated (``NOT``) +query:: Q(question__startswith='Who') | ~Q(pub_date__year=2005) @@ -1175,6 +1176,10 @@ precede the definition of any keyword arguments. For example:: The :source:`OR lookups examples <tests/or_lookups/tests.py>` in Django's unit tests show some possible uses of ``Q``. +.. versionchanged:: 4.1 + + Support for the ``^`` (``XOR``) operator was added. + Comparing objects ================= |
