Ticket #7672: dayofweek_filter-r7866.v2.diff
File dayofweek_filter-r7866.v2.diff, 6.8 KB (added by , 16 years ago) |
---|
-
django/db/models/sql/where.py
152 152 params) 153 153 elif lookup_type in ('range', 'year'): 154 154 return ('%s BETWEEN %%s and %%s' % field_sql, params) 155 elif lookup_type in ('month', 'day' ):155 elif lookup_type in ('month', 'day', 'week_day'): 156 156 return ('%s = %%s' % connection.ops.date_extract_sql(lookup_type, 157 157 field_sql), params) 158 158 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', ' isnull', 'search', 'regex', 'iregex',7 'month', 'day', 'week_day', 'isnull', 'search', 'regex', 'iregex', 8 8 )]) 9 9 10 10 # Size of each "chunk" for get_iterator calls. -
django/db/models/fields/__init__.py
233 233 if hasattr(value, 'as_sql'): 234 234 sql, params = value.as_sql() 235 235 return QueryWrapper(('(%s)' % sql), params) 236 if lookup_type in ('exact', 'regex', 'iregex', 'gt', 'gte', 'lt', 'lte', 'month', 'day', ' search'):236 if lookup_type in ('exact', 'regex', 'iregex', 'gt', 'gte', 'lt', 'lte', 'month', 'day', 'wee k_day', 'search'): 237 237 return [value] 238 238 elif lookup_type in ('range', 'in'): 239 239 return value -
django/db/backends/postgresql/operations.py
26 26 27 27 def date_extract_sql(self, lookup_type, field_name): 28 28 # http://www.postgresql.org/docs/8.0/static/functions-datetime.html#FUNCTIONS-DATETIME-EXTRAC T 29 return "EXTRACT('%s' FROM %s)" % (lookup_type, field_name) 29 if lookup_type == 'week_day': 30 return "EXTRACT('dow' FROM %s)" % field_name 31 else: 32 return "EXTRACT('%s' FROM %s)" % (lookup_type, field_name) 30 33 31 34 def date_trunc_sql(self, lookup_type, field_name): 32 35 # http://www.postgresql.org/docs/8.0/static/functions-datetime.html#FUNCTIONS-DATETIME-TRUNC -
django/db/backends/mysql/base.py
68 68 class DatabaseOperations(BaseDatabaseOperations): 69 69 def date_extract_sql(self, lookup_type, field_name): 70 70 # http://dev.mysql.com/doc/mysql/en/date-and-time-functions.html 71 return "EXTRACT(%s FROM %s)" % (lookup_type.upper(), field_name) 71 if lookup_type == 'week_day': 72 return "DAYOFWEEK(%s)" % field_name 73 else: 74 return "EXTRACT(%s FROM %s)" % (lookup_type.upper(), field_name) 72 75 73 76 def date_trunc_sql(self, lookup_type, field_name): 74 77 fields = ['year', 'month', 'day', 'hour', 'minute', 'second'] -
django/db/backends/oracle/base.py
56 56 57 57 def date_extract_sql(self, lookup_type, field_name): 58 58 # http://download-east.oracle.com/docs/cd/B10501_01/server.920/a96540/functions42a.htm#101716 3 59 return "EXTRACT(%s FROM %s)" % (lookup_type, field_name) 59 if lookup_type == 'week_day': 60 return "TO_CHAR(%s, 'D')" % field_name 61 else: 62 return "EXTRACT(%s FROM %s)" % (lookup_type, field_name) 60 63 61 64 def date_trunc_sql(self, lookup_type, field_name): 62 65 # Oracle uses TRUNC() for both dates and numbers. -
tests/modeltests/basic/models.py
68 68 <Article: Area woman programs in Python> 69 69 >>> Article.objects.get(pub_date__year=2005, pub_date__month=7, pub_date__day=28) 70 70 <Article: Area woman programs in Python> 71 >>> Article.objects.get(pub_date__week_day=5) 72 <Article: Area woman programs in Python> 71 73 72 74 # The "__exact" lookup type can be omitted, as a shortcut. 73 75 >>> Article.objects.get(id=1) … … 82 84 >>> Article.objects.filter(pub_date__year=2005, pub_date__month=7) 83 85 [<Article: Area woman programs in Python>] 84 86 87 >>> Article.objects.filter(pub_date__week_day=5) 88 [<Article: Area woman programs in Python>] 89 >>> Article.objects.filter(pub_date__week_day=6) 90 [] 91 85 92 # Django raises an Article.DoesNotExist exception for get() if the parameters 86 93 # don't match any object. 87 94 >>> Article.objects.get(id__exact=2) … … 94 101 ... 95 102 DoesNotExist: Article matching query does not exist. 96 103 104 >>> Article.objects.get(pub_date__week_day=6) 105 Traceback (most recent call last): 106 ... 107 DoesNotExist: Article matching query does not exist. 108 97 109 # Lookup by a primary key is the most common case, so Django provides a 98 110 # shortcut for primary-key exact lookups. 99 111 # The following is identical to articles.get(id=1). -
docs/db-api.txt
1534 1534 Note this will match any record with a pub_date on the third day of the month, 1535 1535 such as January 3, July 3, etc. 1536 1536 1537 week_day 1538 ~~~~~~~~ 1539 1540 For date/datetime fields, a 'day of the week' match. 1541 1542 Example:: 1543 1544 Entry.objects.filter(pub_date__week_day=2) 1545 1546 SQL equivalent:: 1547 1548 SELECT ... WHERE EXTRACT('dow' FROM pub_date) = '2'; 1549 1550 (The exact SQL syntax varies for each database engine.) 1551 1552 Note this will match any record with a pub_date that falls on a Tuesday (day 2 1553 of the week), regardless of the month or year in which it occurs. Week days 1554 are zero-indexed, with day 0 being Sunday and day 6 being Saturday. 1555 1537 1556 isnull 1538 1557 ~~~~~~ 1539 1558