summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2014-11-12 22:00:48 +0100
committerTim Graham <timograham@gmail.com>2014-11-12 22:01:12 +0100
commitb078ccf8bfcd105873f13141403a6057e430463d (patch)
treedc2a4b8ed7b2071d3f92450411f6e026b8d046b8
parentbcdfa0eb9a7ffdd2938f1365ef93ad8aec0c7fb2 (diff)
[1.6.x] Fixed #23774 -- Clarified QuerySet.order_by() and related models.
Backport of 11b7680d0e from master
-rw-r--r--docs/ref/models/querysets.txt10
1 files changed, 7 insertions, 3 deletions
diff --git a/docs/ref/models/querysets.txt b/docs/ref/models/querysets.txt
index 7f4ff46f56..1e83380200 100644
--- a/docs/ref/models/querysets.txt
+++ b/docs/ref/models/querysets.txt
@@ -284,9 +284,10 @@ and so on for as many models as you want to join. For example::
Entry.objects.order_by('blog__name', 'headline')
If you try to order by a field that is a relation to another model, Django will
-use the default ordering on the related model (or order by the related model's
+use the default ordering on the related model, or order by the related model's
primary key if there is no :attr:`Meta.ordering
-<django.db.models.Options.ordering>` specified. For example::
+<django.db.models.Options.ordering>` specified. For example, since the ``Blog``
+model has no default ordering specified::
Entry.objects.order_by('blog')
@@ -294,7 +295,10 @@ primary key if there is no :attr:`Meta.ordering
Entry.objects.order_by('blog__id')
-...since the ``Blog`` model has no default ordering specified.
+If ``Blog`` had ``ordering = ['name']``, then the first queryset would be
+identical to::
+
+ Entry.objects.order_by('blog__name')
Be cautious when ordering by fields in related models if you are also using
:meth:`distinct()`. See the note in :meth:`distinct` for an explanation of how