Kaydet (Commit) 3e0d7de8 authored tarafından Tim Graham's avatar Tim Graham

[1.7.x] Fixed #23774 -- Clarified QuerySet.order_by() and related models.

Backport of 11b7680d from master
üst 7c44d4be
...@@ -282,9 +282,10 @@ and so on for as many models as you want to join. For example:: ...@@ -282,9 +282,10 @@ and so on for as many models as you want to join. For example::
Entry.objects.order_by('blog__name', 'headline') Entry.objects.order_by('blog__name', 'headline')
If you try to order by a field that is a relation to another model, Django will 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 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') Entry.objects.order_by('blog')
...@@ -292,7 +293,10 @@ primary key if there is no :attr:`Meta.ordering ...@@ -292,7 +293,10 @@ primary key if there is no :attr:`Meta.ordering
Entry.objects.order_by('blog__id') 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')
.. versionadded:: 1.7 .. versionadded:: 1.7
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment