summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
Diffstat (limited to 'docs')
-rw-r--r--docs/ref/models/expressions.txt17
-rw-r--r--docs/releases/4.0.txt3
2 files changed, 20 insertions, 0 deletions
diff --git a/docs/ref/models/expressions.txt b/docs/ref/models/expressions.txt
index 9ab502d244..d45cfbe00a 100644
--- a/docs/ref/models/expressions.txt
+++ b/docs/ref/models/expressions.txt
@@ -410,6 +410,14 @@ The ``Aggregate`` API is as follows:
allows passing a ``distinct`` keyword argument. If set to ``False``
(default), ``TypeError`` is raised if ``distinct=True`` is passed.
+ .. attribute:: empty_aggregate_value
+
+ .. versionadded:: 4.0
+
+ Override :attr:`~django.db.models.Expression.empty_aggregate_value` to
+ ``None`` since most aggregate functions result in ``NULL`` when applied
+ to an empty result set.
+
The ``expressions`` positional arguments can include expressions, transforms of
the model field, or the names of model fields. They will be converted to a
string and used as the ``expressions`` placeholder within the ``template``.
@@ -950,6 +958,15 @@ calling the appropriate methods on the wrapped expression.
in :class:`~django.db.models.expressions.Window`. Defaults to
``False``.
+ .. attribute:: empty_aggregate_value
+
+ .. versionadded:: 4.0
+
+ Tells Django which value should be returned when the expression is used
+ to :meth:`aggregate <django.db.models.query.QuerySet.aggregate>` over
+ an empty result set. Defaults to :py:data:`NotImplemented` which forces
+ the expression to be computed on the database.
+
.. method:: resolve_expression(query=None, allow_joins=True, reuse=None, summarize=False, for_save=False)
Provides the chance to do any pre-processing or validation of
diff --git a/docs/releases/4.0.txt b/docs/releases/4.0.txt
index a9b29d7ce4..c1e64c499a 100644
--- a/docs/releases/4.0.txt
+++ b/docs/releases/4.0.txt
@@ -265,6 +265,9 @@ Models
* :meth:`.QuerySet.bulk_update` now returns the number of objects updated.
+* The new :attr:`.Aggregate.empty_aggregate_value` attribute allows specifying
+ a value to return when the aggregation is used over an empty result set.
+
Requests and Responses
~~~~~~~~~~~~~~~~~~~~~~