mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #24649 -- Allowed using Avg aggregate on non-numeric field types.
This commit is contained in:
@@ -2802,12 +2802,19 @@ by the aggregate.
|
||||
Avg
|
||||
~~~
|
||||
|
||||
.. class:: Avg(expression, output_field=None, **extra)
|
||||
.. class:: Avg(expression, output_field=FloatField(), **extra)
|
||||
|
||||
Returns the mean value of the given expression, which must be numeric.
|
||||
Returns the mean value of the given expression, which must be numeric
|
||||
unless you specify a different ``output_field``.
|
||||
|
||||
* Default alias: ``<field>__avg``
|
||||
* Return type: ``float``
|
||||
* Return type: ``float`` (or the type of whatever ``output_field`` is
|
||||
specified)
|
||||
|
||||
.. versionchanged:: 1.9
|
||||
|
||||
The ``output_field`` parameter was added to allow aggregating over
|
||||
non-numeric columns, such as ``DurationField``.
|
||||
|
||||
Count
|
||||
~~~~~
|
||||
|
||||
@@ -200,6 +200,10 @@ Models
|
||||
(such as :lookup:`exact`, :lookup:`gt`, :lookup:`lt`, etc.). For example:
|
||||
``Entry.objects.filter(pub_date__month__gt=6)``.
|
||||
|
||||
* You can specify the ``output_field`` parameter of the
|
||||
:class:`~django.db.models.Avg` aggregate in order to aggregate over
|
||||
non-numeric columns, such as ``DurationField``.
|
||||
|
||||
CSRF
|
||||
^^^^
|
||||
|
||||
|
||||
Reference in New Issue
Block a user