Ticket #9834: aggregation-class.diff

File aggregation-class.diff, 3.1 KB (added by Alex, 7 years ago)
  • django/db/models/aggregates.py

    diff --git a/django/db/models/aggregates.py b/django/db/models/aggregates.py
    index 9db0910..e9c4213 100644
    a b class Aggregate(object): 
    66    """
    77    Default Aggregate definition.
    88    """
    9     def __init__(self, name, lookup, **extra):
    10         self.name = name
     9    def __init__(self, lookup, **extra):
    1110        self.lookup = lookup
    1211        self.extra = extra
    1312
    class Aggregate(object): 
    1918        return getattr(engine, self.name)(col, source, is_summary, **self.extra)
    2019
    2120class Max(Aggregate):
    22     def __init__(self, lookup):
    23         super(Max, self).__init__('Max', lookup)
    24 
     21    name = 'Max'
     22   
    2523class Min(Aggregate):
    26     def __init__(self, lookup):
    27         super(Min, self).__init__('Min', lookup)
     24    name = 'Min'
    2825
    2926class Avg(Aggregate):
    30     def __init__(self, lookup):
    31         super(Avg, self).__init__('Avg', lookup)
     27    name = 'Avg'
    3228
    3329class Sum(Aggregate):
    34     def __init__(self, lookup):
    35         super(Sum, self).__init__('Sum', lookup)
     30    name = 'Sum'
    3631
    3732class Count(Aggregate):
     33    name = 'Count'
     34   
    3835    def __init__(self, lookup, distinct=False):
    39         super(Count, self).__init__('Count', lookup, distinct=distinct)
     36        super(Count, self).__init__(lookup, distinct=distinct)
  • django/db/models/sql/aggregates.py

    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): 
    1111    is_computed = False
    1212    sql_template = '%(function)s(%(field)s)'
    1313
    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):
    1615        self.col = col
    1716        self.is_summary = is_summary
    1817        self.extra = extra
    class Aggregate(object): 
    5049
    5150
    5251class 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   
    5654class 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'
    5956
    6057class Avg(Aggregate):
    6158    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'
    6560
    6661class 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'
    6963
    7064class Count(Aggregate):
    7165    is_ordinal = True
     66    sql_function = 'COUNT'
    7267    sql_template = '%(function)s(%(distinct)s%(field)s)'
    7368
    7469    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 '')
Back to Top