Fixed #30253 -- Doc'd how to order nulls in QuerySet.order_by().

This commit is contained in:
Paul Wayper 2019-03-14 14:08:02 +11:00 committed by Tim Graham
parent 386d89ab55
commit 1025e76429
1 changed files with 5 additions and 1 deletions

View File

@ -312,10 +312,14 @@ identical to::
Entry.objects.order_by('blog__name') Entry.objects.order_by('blog__name')
You can also order by :doc:`query expressions </ref/models/expressions>` by You can also order by :doc:`query expressions </ref/models/expressions>` by
calling ``asc()`` or ``desc()`` on the expression:: calling :meth:`~.Expression.asc` or :meth:`~.Expression.desc` on the
expression::
Entry.objects.order_by(Coalesce('summary', 'headline').desc()) Entry.objects.order_by(Coalesce('summary', 'headline').desc())
:meth:`~.Expression.asc` and :meth:`~.Expression.desc` have arguments
(``nulls_first`` and ``nulls_last``) that control how null values are sorted.
Be cautious when ordering by fields in related models if you are also using 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 :meth:`distinct()`. See the note in :meth:`distinct` for an explanation of how
related model ordering can change the expected results. related model ordering can change the expected results.