def add_date_select(self, field_name, lookup_type, order='ASC'): """ Converts the query into a date extraction query. """ try: result = self.setup_joins(field_name.split(LOOKUP_SEP), self.get_meta(), self.get_initial_alias(), False) except FieldError: raise FieldDoesNotExist("%s has no field named '%s'" % (self.model._meta.object_name, field_name)) field = result[0] assert isinstance(field, DateField), "%r isn't a DateField." \ % field.name alias = result[3][-1] select = Date((alias, field.column), lookup_type) self.select = [select] self.select_fields = [None] self.select_related = False # See #7097. self.set_extra_mask([]) self.distinct = True self.order_by = order == 'ASC' and [1] or [-1] if field.null: self.add_filter(("%s__isnull" % field_name, False))
def add_date_select(self, field, lookup_type, order='ASC'): """ Converts the query into a date extraction query. """ result = self.setup_joins([field.name], self.get_meta(), self.get_initial_alias(), False) alias = result[3][-1] select = Date((alias, field.column), lookup_type, self.connection.ops.date_trunc_sql) self.select = [select] self.select_fields = [None] self.select_related = False # See #7097. self.distinct = True self.order_by = order == 'ASC' and [1] or [-1]
def _get_select(self, col, lookup_type): return Date(col, lookup_type)