Fixed #26067 -- Added ordering support to ArrayAgg and StringAgg.

This commit is contained in:
Floris den Hengst 2016-07-05 11:47:24 +02:00 committed by Tim Graham
parent 2a0116266c
commit 96199e562d
5 changed files with 146 additions and 12 deletions

View file

@ -22,7 +22,7 @@ General-purpose aggregation functions
``ArrayAgg``
------------
.. class:: ArrayAgg(expression, distinct=False, filter=None, **extra)
.. class:: ArrayAgg(expression, distinct=False, filter=None, ordering=(), **extra)
Returns a list of values, including nulls, concatenated into an array.
@ -31,6 +31,22 @@ General-purpose aggregation functions
An optional boolean argument that determines if array values
will be distinct. Defaults to ``False``.
.. attribute:: ordering
.. versionadded:: 2.2
An optional string of a field name (with an optional ``"-"`` prefix
which indicates descending order) or an expression (or a tuple or list
of strings and/or expressions) that specifies the ordering of the
elements in the result list.
Examples::
'some_field'
'-some_field'
from django.db.models import F
F('some_field').desc()
``BitAnd``
----------
@ -73,7 +89,7 @@ General-purpose aggregation functions
``StringAgg``
-------------
.. class:: StringAgg(expression, delimiter, distinct=False, filter=None)
.. class:: StringAgg(expression, delimiter, distinct=False, filter=None, ordering=())
Returns the input values concatenated into a string, separated by
the ``delimiter`` string.
@ -87,6 +103,17 @@ General-purpose aggregation functions
An optional boolean argument that determines if concatenated values
will be distinct. Defaults to ``False``.
.. attribute:: ordering
.. versionadded:: 2.2
An optional string of a field name (with an optional ``"-"`` prefix
which indicates descending order) or an expression (or a tuple or list
of strings and/or expressions) that specifies the ordering of the
elements in the result string.
Examples are the same as for :attr:`ArrayAgg.ordering`.
Aggregate functions for statistics
==================================