mirror of
https://github.com/django/django.git
synced 2025-08-02 18:13:02 +00:00
Fixed #24649 -- Allowed using Avg aggregate on non-numeric field types.
This commit is contained in:
parent
26996e2d55
commit
2d76b61dc2
7 changed files with 46 additions and 15 deletions
|
@ -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
|
||||
^^^^
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue