Fixed #24649 -- Allowed using Avg aggregate on non-numeric field types.

This commit is contained in:
Tim Graham 2015-04-23 20:13:24 -04:00
parent 26996e2d55
commit 2d76b61dc2
7 changed files with 46 additions and 15 deletions

View file

@ -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
~~~~~

View file

@ -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
^^^^