summaryrefslogtreecommitdiff
path: root/docs/ref
diff options
context:
space:
mode:
authorColm O'Connor <colm.oconnor.github@gmail.com>2018-06-21 21:01:53 +0100
committerTim Graham <timograham@gmail.com>2018-06-29 20:56:45 -0400
commite410dce696d4b8aa8966e7c0931129015a6d84df (patch)
tree9ef54bbe8ddac59326485cdd71891c065c0467f8 /docs/ref
parent58a0a84c3817de94f1b108697b23b57f78d67425 (diff)
[2.1.x] Fixed #21333 -- Doc'd the & and | queryset operators.
Backport of c530428d360daf904c9e98515ea836643a73a54c from master
Diffstat (limited to 'docs/ref')
-rw-r--r--docs/ref/models/querysets.txt40
1 files changed, 40 insertions, 0 deletions
diff --git a/docs/ref/models/querysets.txt b/docs/ref/models/querysets.txt
index b18f5ab3e6..c200faf825 100644
--- a/docs/ref/models/querysets.txt
+++ b/docs/ref/models/querysets.txt
@@ -1758,6 +1758,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
-----------------------------------------