Ticket #9796: aggregation-class.diff

File aggregation-class.diff, 1.5 KB (added by Alex Gaynor, 15 years ago)
  • django/db/models/sql/aggregates.py

    diff --git a/django/db/models/sql/aggregates.py b/django/db/models/sql/aggregates.py
    index b31e11d..b1213a7 100644
    a b class Aggregate(object):  
    77    """
    88    Default SQL Aggregate.
    99    """
     10    is_ordinal = False
     11    is_computed = False
     12    sql_template = '%(function)s(%(field)s)'
     13
    1014    def __init__(self, function, lookup, **extra):
    1115        self.sql_function = function
    1216        self.lookup = lookup
    1317        self.extra = extra
    14         self.is_ordinal = False
    15         self.is_computed = False
    16         self.sql_template = '%(function)s(%(field)s)'
    1718
    1819    def get_internal_type(self):
    1920        "Return the internal data type of the field being aggregated"
    class Min(Aggregate):  
    5354        super(Min, self).__init__('MIN', lookup)
    5455
    5556class Avg(Aggregate):
     57    is_computed = True
     58   
    5659    def __init__(self, lookup):
    5760        super(Avg, self).__init__('AVG', lookup)
    58         self.is_computed = True
     61
    5962
    6063class Sum(Aggregate):
    6164    def __init__(self, lookup):
    6265        super(Sum, self).__init__('SUM', lookup)
    6366
    6467class Count(Aggregate):
     68    is_ordinal = True
     69    sql_template = '%(function)s(%(distinct)s%(field)s)'
     70   
    6571    def __init__(self, lookup, distinct=False):
    6672        super(Count, self).__init__('COUNT', lookup, distinct=distinct and 'DISTINCT ' or '')
    67         self.sql_template = '%(function)s(%(distinct)s%(field)s)'
    68         self.is_ordinal = True
     73
Back to Top