web/lib/django/db/models/sql/aggregates.py
changeset 29 cc9b7e14412b
parent 0 0d40e90630ef
equal deleted inserted replaced
28:b758351d191f 29:cc9b7e14412b
    70 
    70 
    71     def relabel_aliases(self, change_map):
    71     def relabel_aliases(self, change_map):
    72         if isinstance(self.col, (list, tuple)):
    72         if isinstance(self.col, (list, tuple)):
    73             self.col = (change_map.get(self.col[0], self.col[0]), self.col[1])
    73             self.col = (change_map.get(self.col[0], self.col[0]), self.col[1])
    74 
    74 
    75     def as_sql(self, quote_func=None):
    75     def as_sql(self, qn, connection):
    76         "Return the aggregate, rendered as SQL."
    76         "Return the aggregate, rendered as SQL."
    77         if not quote_func:
       
    78             quote_func = lambda x: x
       
    79 
    77 
    80         if hasattr(self.col, 'as_sql'):
    78         if hasattr(self.col, 'as_sql'):
    81             field_name = self.col.as_sql(quote_func)
    79             field_name = self.col.as_sql(qn, connection)
    82         elif isinstance(self.col, (list, tuple)):
    80         elif isinstance(self.col, (list, tuple)):
    83             field_name = '.'.join([quote_func(c) for c in self.col])
    81             field_name = '.'.join([qn(c) for c in self.col])
    84         else:
    82         else:
    85             field_name = self.col
    83             field_name = self.col
    86 
    84 
    87         params = {
    85         params = {
    88             'function': self.sql_function,
    86             'function': self.sql_function,
   125     is_computed = True
   123     is_computed = True
   126 
   124 
   127     def __init__(self, col, sample=False, **extra):
   125     def __init__(self, col, sample=False, **extra):
   128         super(Variance, self).__init__(col, **extra)
   126         super(Variance, self).__init__(col, **extra)
   129         self.sql_function = sample and 'VAR_SAMP' or 'VAR_POP'
   127         self.sql_function = sample and 'VAR_SAMP' or 'VAR_POP'
   130