diff options
| author | Colm O'Connor <colm.oconnor.github@gmail.com> | 2018-06-21 21:01:53 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2018-06-29 20:39:18 -0400 |
| commit | c530428d360daf904c9e98515ea836643a73a54c (patch) | |
| tree | d22a04ac6558b4fb8a451b607facca36682c6417 /docs | |
| parent | 48b327aef1095a8978ba8d320d706949c1ec41da (diff) | |
Fixed #21333 -- Doc'd the & and | queryset operators.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/ref/models/querysets.txt | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/docs/ref/models/querysets.txt b/docs/ref/models/querysets.txt index bae2c33a1d..b190ff02b0 100644 --- a/docs/ref/models/querysets.txt +++ b/docs/ref/models/querysets.txt @@ -1750,6 +1750,46 @@ See the :doc:`/topics/db/sql` for more information. filtering. As such, it should generally be called from the ``Manager`` or from a fresh ``QuerySet`` instance. +Operators that return new ``QuerySet``\s +---------------------------------------- + +Combined querysets must use the same model. + +AND (``&``) +~~~~~~~~~~~ + +Combines two ``QuerySet``\s using the SQL ``AND`` operator. + +The following are equivalent:: + + Model.objects.filter(x=1) & Model.objects.filter(y=2) + Model.objects.filter(x=1, y=2) + from django.db.models import Q + Model.objects.filter(Q(x=1) & Q(y=2)) + +SQL equivalent: + +.. code-block:: sql + + SELECT ... WHERE x=1 AND y=2 + +OR (``|``) +~~~~~~~~~~ + +Combines two ``QuerySet``\s using the SQL ``OR`` operator. + +The following are equivalent:: + + Model.objects.filter(x=1) | Model.objects.filter(y=2) + from django.db.models import Q + Model.objects.filter(Q(x=1) | Q(y=2)) + +SQL equivalent: + +.. code-block:: sql + + SELECT ... WHERE x=1 OR y=2 + Methods that do not return ``QuerySet``\s ----------------------------------------- |
