diff options
| author | Dima Kudosh <LagMegantic@yandex.ru> | 2017-06-25 21:17:13 +0300 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2017-09-05 19:10:20 -0400 |
| commit | 093fd479d6be1790c6dc174f9df3a895b50e8a2f (patch) | |
| tree | 3829042666e7e74d62cc364363b4a18c29d86228 /docs | |
| parent | 3d2c3905a606f373d1b4ad386ad8343112f384f7 (diff) | |
Fixed #28335 -- Allowed query expressions in Meta.ordering.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/ref/models/options.txt | 18 | ||||
| -rw-r--r-- | docs/releases/2.0.txt | 3 |
2 files changed, 18 insertions, 3 deletions
diff --git a/docs/ref/models/options.txt b/docs/ref/models/options.txt index bf8cf10c33..33ff581d39 100644 --- a/docs/ref/models/options.txt +++ b/docs/ref/models/options.txt @@ -256,9 +256,10 @@ Django quotes column and table names behind the scenes. ordering = ['-order_date'] - This is a tuple or list of strings. Each string is a field name with an optional - "-" prefix, which indicates descending order. Fields without a leading "-" will - be ordered ascending. Use the string "?" to order randomly. + This is a tuple or list of strings and/or query expressions. Each string is + a field name with an optional "-" prefix, which indicates descending order. + Fields without a leading "-" will be ordered ascending. Use the string "?" + to order randomly. For example, to order by a ``pub_date`` field ascending, use this:: @@ -272,9 +273,20 @@ Django quotes column and table names behind the scenes. ordering = ['-pub_date', 'author'] + You can also use :doc:`query expressions </ref/models/expressions>`. To + order by ``author`` ascending and make null values sort last, use this:: + + from django.db.models import F + + ordering = [F('author').asc(nulls_last=True)] + Default ordering also affects :ref:`aggregation queries <aggregation-ordering-interaction>`. + .. versionchanged:: 2.0 + + Support for query expressions was added. + .. warning:: Ordering is not a free operation. Each field you add to the ordering diff --git a/docs/releases/2.0.txt b/docs/releases/2.0.txt index 4f92927c1e..a8530d11c2 100644 --- a/docs/releases/2.0.txt +++ b/docs/releases/2.0.txt @@ -283,6 +283,9 @@ Models different conditionals <conditional-aggregation>` to multiple aggregations over the same fields or relations. +* Added support for expressions in :attr:`Meta.ordering + <django.db.models.Options.ordering>`. + Requests and Responses ~~~~~~~~~~~~~~~~~~~~~~ |
