diff --git a/django/db/models/aggregates.py b/django/db/models/aggregates.py
index 9db0910..e9c4213 100644
|
a
|
b
|
class Aggregate(object):
|
| 6 | 6 | """ |
| 7 | 7 | Default Aggregate definition. |
| 8 | 8 | """ |
| 9 | | def __init__(self, name, lookup, **extra): |
| 10 | | self.name = name |
| | 9 | def __init__(self, lookup, **extra): |
| 11 | 10 | self.lookup = lookup |
| 12 | 11 | self.extra = extra |
| 13 | 12 | |
| … |
… |
class Aggregate(object):
|
| 19 | 18 | return getattr(engine, self.name)(col, source, is_summary, **self.extra) |
| 20 | 19 | |
| 21 | 20 | class Max(Aggregate): |
| 22 | | def __init__(self, lookup): |
| 23 | | super(Max, self).__init__('Max', lookup) |
| 24 | | |
| | 21 | name = 'Max' |
| | 22 | |
| 25 | 23 | class Min(Aggregate): |
| 26 | | def __init__(self, lookup): |
| 27 | | super(Min, self).__init__('Min', lookup) |
| | 24 | name = 'Min' |
| 28 | 25 | |
| 29 | 26 | class Avg(Aggregate): |
| 30 | | def __init__(self, lookup): |
| 31 | | super(Avg, self).__init__('Avg', lookup) |
| | 27 | name = 'Avg' |
| 32 | 28 | |
| 33 | 29 | class Sum(Aggregate): |
| 34 | | def __init__(self, lookup): |
| 35 | | super(Sum, self).__init__('Sum', lookup) |
| | 30 | name = 'Sum' |
| 36 | 31 | |
| 37 | 32 | class Count(Aggregate): |
| | 33 | name = 'Count' |
| | 34 | |
| 38 | 35 | def __init__(self, lookup, distinct=False): |
| 39 | | super(Count, self).__init__('Count', lookup, distinct=distinct) |
| | 36 | super(Count, self).__init__(lookup, distinct=distinct) |
diff --git a/django/db/models/sql/aggregates.py b/django/db/models/sql/aggregates.py
index f15e80f..f00634c 100644
|
a
|
b
|
class Aggregate(object):
|
| 11 | 11 | is_computed = False |
| 12 | 12 | sql_template = '%(function)s(%(field)s)' |
| 13 | 13 | |
| 14 | | def __init__(self, function, col, source=None, is_summary=False, **extra): |
| 15 | | self.sql_function = function |
| | 14 | def __init__(self, col, source=None, is_summary=False, **extra): |
| 16 | 15 | self.col = col |
| 17 | 16 | self.is_summary = is_summary |
| 18 | 17 | self.extra = extra |
| … |
… |
class Aggregate(object):
|
| 50 | 49 | |
| 51 | 50 | |
| 52 | 51 | class Max(Aggregate): |
| 53 | | def __init__(self, col, source=None, is_summary=False): |
| 54 | | super(Max, self).__init__('MAX', col, source, is_summary) |
| 55 | | |
| | 52 | sql_function = 'MAX' |
| | 53 | |
| 56 | 54 | class Min(Aggregate): |
| 57 | | def __init__(self, col, source=None, is_summary=False): |
| 58 | | super(Min, self).__init__('MIN', col, source, is_summary) |
| | 55 | sql_function = 'MIN' |
| 59 | 56 | |
| 60 | 57 | class Avg(Aggregate): |
| 61 | 58 | is_computed = True |
| 62 | | |
| 63 | | def __init__(self, col, source=None, is_summary=False): |
| 64 | | super(Avg, self).__init__('AVG', col, source, is_summary) |
| | 59 | sql_function = 'AVG' |
| 65 | 60 | |
| 66 | 61 | class Sum(Aggregate): |
| 67 | | def __init__(self, col, source=None, is_summary=False): |
| 68 | | super(Sum, self).__init__('SUM', col, source, is_summary) |
| | 62 | sql_function = 'SUM' |
| 69 | 63 | |
| 70 | 64 | class Count(Aggregate): |
| 71 | 65 | is_ordinal = True |
| | 66 | sql_function = 'COUNT' |
| 72 | 67 | sql_template = '%(function)s(%(distinct)s%(field)s)' |
| 73 | 68 | |
| 74 | 69 | def __init__(self, col, source=None, is_summary=False, distinct=False): |
| 75 | | super(Count, self).__init__('COUNT', col, source, is_summary, distinct=distinct and 'DISTINCT ' or '') |
| | 70 | super(Count, self).__init__(col, source, is_summary, distinct=distinct and 'DISTINCT ' or '') |