web/lib/django/db/models/sql/datastructures.py
changeset 29 cc9b7e14412b
parent 0 0d40e90630ef
equal deleted inserted replaced
28:b758351d191f 29:cc9b7e14412b
    27 
    27 
    28 class Date(object):
    28 class Date(object):
    29     """
    29     """
    30     Add a date selection column.
    30     Add a date selection column.
    31     """
    31     """
    32     def __init__(self, col, lookup_type, date_sql_func):
    32     def __init__(self, col, lookup_type):
    33         self.col = col
    33         self.col = col
    34         self.lookup_type = lookup_type
    34         self.lookup_type = lookup_type
    35         self.date_sql_func = date_sql_func
       
    36 
    35 
    37     def relabel_aliases(self, change_map):
    36     def relabel_aliases(self, change_map):
    38         c = self.col
    37         c = self.col
    39         if isinstance(c, (list, tuple)):
    38         if isinstance(c, (list, tuple)):
    40             self.col = (change_map.get(c[0], c[0]), c[1])
    39             self.col = (change_map.get(c[0], c[0]), c[1])
    41 
    40 
    42     def as_sql(self, quote_func=None):
    41     def as_sql(self, qn, connection):
    43         if not quote_func:
       
    44             quote_func = lambda x: x
       
    45         if isinstance(self.col, (list, tuple)):
    42         if isinstance(self.col, (list, tuple)):
    46             col = '%s.%s' % tuple([quote_func(c) for c in self.col])
    43             col = '%s.%s' % tuple([qn(c) for c in self.col])
    47         else:
    44         else:
    48             col = self.col
    45             col = self.col
    49         return self.date_sql_func(self.lookup_type, col)
    46         return connection.ops.date_trunc_sql(self.lookup_type, col)
    50