summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2017-09-29 00:37:49 -0400
committerTim Graham <timograham@gmail.com>2017-09-29 08:20:08 -0400
commitdeb3b58b362ef393b49702a3fef28774c9c3f53e (patch)
treeb04899fe03f348f27f1d1cb1a936d3754650f1d3
parent8368d5a4006d84abacbcf53b9688a8f84ccf6f0c (diff)
[2.0.x] Refs #28492 -- Defined aggregates' output_field at the class level.
Missed in 08654a99bbdd09049d682ae57cc94241534b29f0. Backport of f1b713024e3a1e8c6361ea407cb8248224f7cc82 from master
-rw-r--r--django/db/models/aggregates.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/django/db/models/aggregates.py b/django/db/models/aggregates.py
index 4ed763cfe1..3c0434f907 100644
--- a/django/db/models/aggregates.py
+++ b/django/db/models/aggregates.py
@@ -110,6 +110,7 @@ class Count(Aggregate):
function = 'COUNT'
name = 'Count'
template = '%(function)s(%(distinct)s%(expressions)s)'
+ output_field = IntegerField()
def __init__(self, expression, distinct=False, filter=None, **extra):
if expression == '*':
@@ -118,7 +119,7 @@ class Count(Aggregate):
raise ValueError('Star cannot be used with filter. Please specify a field.')
super().__init__(
expression, distinct='DISTINCT ' if distinct else '',
- output_field=IntegerField(), filter=filter, **extra
+ filter=filter, **extra
)
def _get_repr_options(self):
@@ -141,10 +142,11 @@ class Min(Aggregate):
class StdDev(Aggregate):
name = 'StdDev'
+ output_field = FloatField()
def __init__(self, expression, sample=False, **extra):
self.function = 'STDDEV_SAMP' if sample else 'STDDEV_POP'
- super().__init__(expression, output_field=FloatField(), **extra)
+ super().__init__(expression, **extra)
def _get_repr_options(self):
options = super()._get_repr_options()
@@ -167,10 +169,11 @@ class Sum(Aggregate):
class Variance(Aggregate):
name = 'Variance'
+ output_field = FloatField()
def __init__(self, expression, sample=False, **extra):
self.function = 'VAR_SAMP' if sample else 'VAR_POP'
- super().__init__(expression, output_field=FloatField(), **extra)
+ super().__init__(expression, **extra)
def _get_repr_options(self):
options = super()._get_repr_options()