Ticket #12489: django12489.diff
File django12489.diff, 7.2 KB (added by , 14 years ago) |
---|
-
tests/modeltests/basic/tests.py
50 50 self.assertEqual(Article.objects.get(pub_date__year=2005, pub_date__month=7), a) 51 51 self.assertEqual(Article.objects.get(pub_date__year=2005, pub_date__month=7, pub_date__day=28), a) 52 52 self.assertEqual(Article.objects.get(pub_date__week_day=5), a) 53 self.assertEqual(Article.objects.get(pub_date__week_of_year=30), a) 54 self.assertEqual(Article.objects.get(pub_date__day_of_year=209), a) 53 55 54 56 # The "__exact" lookup type can be omitted, as a shortcut. 55 57 self.assertEqual(Article.objects.get(id=a.id), a) -
django/db/models/sql/where.py
199 199 params) 200 200 elif lookup_type in ('range', 'year'): 201 201 return ('%s BETWEEN %%s and %%s' % field_sql, params) 202 elif lookup_type in ('month', 'day', 'week_day' ):202 elif lookup_type in ('month', 'day', 'week_day', 'week_of_year', 'day_of_year'): 203 203 return ('%s = %%s' % connection.ops.date_extract_sql(lookup_type, field_sql), 204 204 params) 205 205 elif lookup_type == 'isnull': -
django/db/models/sql/constants.py
4 4 QUERY_TERMS = dict([(x, None) for x in ( 5 5 'exact', 'iexact', 'contains', 'icontains', 'gt', 'gte', 'lt', 'lte', 'in', 6 6 'startswith', 'istartswith', 'endswith', 'iendswith', 'range', 'year', 7 'month', 'day', 'week_day', ' isnull', 'search', 'regex', 'iregex',7 'month', 'day', 'week_day', 'week_of_year', 'day_of_year', 'isnull', 'search', 'regex', 'iregex', 8 8 )]) 9 9 10 10 # Size of each "chunk" for get_iterator calls. -
django/db/models/fields/__init__.py
283 283 return value._prepare() 284 284 285 285 if lookup_type in ( 286 'regex', 'iregex', 'month', 'day', 'week_day', ' search',287 ' contains', 'icontains', 'iexact', 'startswith', 'istartswith',286 'regex', 'iregex', 'month', 'day', 'week_day', 'week_of_year', 'day_of_year', 287 'search','contains', 'icontains', 'iexact', 'startswith', 'istartswith', 288 288 'endswith', 'iendswith', 'isnull' 289 289 ): 290 290 return value … … 317 317 sql, params = value._as_sql(connection=connection) 318 318 return QueryWrapper(('(%s)' % sql), params) 319 319 320 if lookup_type in ('regex', 'iregex', 'month', 'day', 'week_day', ' search'):320 if lookup_type in ('regex', 'iregex', 'month', 'day', 'week_day', 'week_of_year', 'day_of_year', 'search'): 321 321 return [value] 322 322 elif lookup_type in ('exact', 'gt', 'gte', 'lt', 'lte'): 323 323 return [self.get_db_prep_value(value, connection=connection, prepared=prepared)] … … 639 639 def get_prep_lookup(self, lookup_type, value): 640 640 # For "__month", "__day", and "__week_day" lookups, convert the value 641 641 # to an int so the database backend always sees a consistent type. 642 if lookup_type in ('month', 'day', 'week_day' ):642 if lookup_type in ('month', 'day', 'week_day', 'week_of_year', 'day_of_year'): 643 643 return int(value) 644 644 return super(DateField, self).get_prep_lookup(lookup_type, value) 645 645 -
django/db/backends/postgresql/operations.py
24 24 if lookup_type == 'week_day': 25 25 # For consistency across backends, we return Sunday=1, Saturday=7. 26 26 return "EXTRACT('dow' FROM %s) + 1" % field_name 27 elif lookup_type == 'day_of_year': 28 # http://www.postgresql.org/docs/8.3/static/functions-formatting.html 29 return "TO_CHAR(%s, 'DDD')" % field_name 30 elif lookup_type == 'week_of_year': 31 # http://www.postgresql.org/docs/8.3/static/functions-formatting.html 32 # returns ISO week of the year. 33 return "TO_CHAR(%s, 'IW')" % field_name 27 34 else: 28 35 return "EXTRACT('%s' FROM %s)" % (lookup_type, field_name) 29 36 -
django/db/backends/sqlite3/base.py
256 256 dt = util.typecast_timestamp(dt) 257 257 except (ValueError, TypeError): 258 258 return None 259 260 _, iso_week, iso_week_day = dt.isocalendar() 261 259 262 if lookup_type == 'week_day': 260 return (dt.isoweekday() % 7) + 1 263 return (iso_week_day % 7) + 1 264 elif lookup_type == 'week_of_year': 265 return iso_week 266 elif lookup_type == 'day_of_year': 267 return int(dt.strftime('%j')) 261 268 else: 262 269 return getattr(dt, lookup_type) 263 270 -
django/db/backends/mysql/base.py
155 155 # DAYOFWEEK() returns an integer, 1-7, Sunday=1. 156 156 # Note: WEEKDAY() returns 0-6, Monday=0. 157 157 return "DAYOFWEEK(%s)" % field_name 158 elif lookup_type == 'day_of_year': 159 # DAYOFYEAR() returns the day of the year (1-366) 160 return "DAYOFYEAR(%s)" % field_name 161 elif lookup_type == 'week_of_year': 162 # WEEKOFYEAR() returns the ISO week of the year (1-53). 163 # The first week having 4 or more days in the year is considered week 1. 164 return "WEEKOFYEAR(%s)" % field_name 165 158 166 else: 159 167 return "EXTRACT(%s FROM %s)" % (lookup_type.upper(), field_name) 160 168 -
django/db/backends/oracle/base.py
115 115 if lookup_type == 'week_day': 116 116 # TO_CHAR(field, 'D') returns an integer from 1-7, where 1=Sunday. 117 117 return "TO_CHAR(%s, 'D')" % field_name 118 elif lookup_type == 'day_of_year': 119 # TO_CHAR(field, 'DDD') returns an integer from 1-366, representing the day of the year. 120 return "TO_CHAR(%s, 'DDD')" % field_name 121 elif lookup_type == 'week_of_year': 122 # TO_CHAR(field, 'IW') returns an integer from 1-53, representing the ISO week of the year. 123 return "TO_CHAR(%s, 'IW')" % field_name 118 124 else: 119 125 return "EXTRACT(%s FROM %s)" % (lookup_type, field_name) 120 126