Ticket #13935: 13935.diff
File 13935.diff, 2.5 KB (added by , 14 years ago) |
---|
-
db/models/sql/subqueries.py
188 188 """ 189 189 Converts the query into a date extraction query. 190 190 """ 191 result = self.setup_joins([field.name], self.get_meta(), 192 self.get_initial_alias(), False) 191 from django.db.models.fields import DateField 192 193 if isinstance(field, str): 194 parts = field.split(LOOKUP_SEP) 195 else: 196 parts = [field.name] 197 198 try: 199 result = self.setup_joins(parts, self.get_meta(), 200 self.get_initial_alias(), False) 201 except FieldError: 202 from django.db.models.fields import FieldDoesNotExist 203 204 raise FieldDoesNotExist('%s has no field named %r' % (self.get_meta().object_name, parts[0])) 205 206 field = result[0] 207 assert isinstance(field, DateField), "%r isn't a DateField." \ 208 % field.name 209 193 210 alias = result[3][-1] 194 211 select = Date((alias, field.column), lookup_type) 195 212 self.select = [select] … … 199 216 self.distinct = True 200 217 self.order_by = order == 'ASC' and [1] or [-1] 201 218 219 if field.null: 220 self.add_filter(('%s__isnull' % field.name, False)) 221 202 222 class AggregateQuery(Query): 203 223 """ 204 224 An AggregateQuery takes another query as a parameter to the FROM -
db/models/query.py
988 988 self.query.clear_deferred_loading() 989 989 self.query = self.query.clone(klass=sql.DateQuery, setup=True) 990 990 self.query.select = [] 991 field = self.model._meta.get_field(self._field_name, many_to_many=False)992 assert isinstance(field, DateField), "%r isn't a DateField." \993 % field.name994 self.query.add_date_select(field, self._kind, self._order)995 if field.null:996 self.query.add_filter(('%s__isnull' % field.name, False))997 991 992 # all logic is gone there, because we need to use query.setup_joins 993 # to guess the real field from something like "article__pub_date" 994 self.query.add_date_select(self._field_name, self._kind, self._order) 995 998 996 def _clone(self, klass=None, setup=False, **kwargs): 999 997 c = super(DateQuerySet, self)._clone(klass, False, **kwargs) 1000 998 c._field_name = self._field_name