diff options
| author | Vyacheslav Ver <vvvyacheslav23@gmail.com> | 2019-05-16 19:12:17 +0300 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2019-06-11 12:02:02 +0200 |
| commit | 36766e1a28632f87eedc532c4bc9a5a1c1c8a380 (patch) | |
| tree | ef100f26559850eefdae32947553aeda650083b8 /docs/ref/models/expressions.txt | |
| parent | d5d22e10903eb7122eeeffa7626ba13574bf5435 (diff) | |
[2.2.x] Fixed #30486 -- Fixed the default value of Aggregate.distinct and updated example of custom aggregate functions.
Backport of 76b3fc5c8d8dffb441aaa08f75833888be2107af from master
Diffstat (limited to 'docs/ref/models/expressions.txt')
| -rw-r--r-- | docs/ref/models/expressions.txt | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/docs/ref/models/expressions.txt b/docs/ref/models/expressions.txt index 460a7f70d4..a26e918e70 100644 --- a/docs/ref/models/expressions.txt +++ b/docs/ref/models/expressions.txt @@ -381,7 +381,7 @@ The ``Aggregate`` API is as follows: A class attribute, as a format string, that describes the SQL that is generated for this aggregate. Defaults to - ``'%(function)s( %(expressions)s )'``. + ``'%(function)s(%(distinct)s%(expressions)s)'``. .. attribute:: function @@ -444,20 +444,19 @@ SQL that is generated. Here's a brief example:: from django.db.models import Aggregate - class Count(Aggregate): - # supports COUNT(distinct field) - function = 'COUNT' - template = '%(function)s(%(distinct)s%(expressions)s)' + class Sum(Aggregate): + # Supports SUM(ALL field). + function = 'SUM' + template = '%(function)s(%(all_values)s%(expressions)s)' + allow_distinct = False - def __init__(self, expression, distinct=False, **extra): + def __init__(self, expression, all_values=False, **extra): super().__init__( expression, - distinct='DISTINCT ' if distinct else '', - output_field=IntegerField(), + all_values='ALL ' if all_values else '', **extra ) - ``Value()`` expressions ----------------------- |
