diff options
| author | Karen Tracey <kmtracey@gmail.com> | 2009-02-08 05:08:06 +0000 |
|---|---|---|
| committer | Karen Tracey <kmtracey@gmail.com> | 2009-02-08 05:08:06 +0000 |
| commit | addd3df3bd39730cd82c52d9726c9b7dbf1bdb8f (patch) | |
| tree | e648cbb129dfd103af1d278aaafc0a7007ce95ea /django/db/models | |
| parent | 0326574d0ecf2eeded92d66855822dd2e602297f (diff) | |
Fixed #7672 -- Added a 'week_day' lookup type. Many thanks to Ross Poulton for the proposal and implementation on all built-in database backends..
git-svn-id: http://code.djangoproject.com/svn/django/trunk@9818 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db/models')
| -rw-r--r-- | django/db/models/fields/__init__.py | 8 | ||||
| -rw-r--r-- | django/db/models/sql/constants.py | 2 | ||||
| -rw-r--r-- | django/db/models/sql/where.py | 6 |
3 files changed, 8 insertions, 8 deletions
diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py index 274b5b4327..41e8c06b80 100644 --- a/django/db/models/fields/__init__.py +++ b/django/db/models/fields/__init__.py @@ -201,7 +201,7 @@ class Field(object): sql, params = value.as_sql() return QueryWrapper(('(%s)' % sql), params) - if lookup_type in ('regex', 'iregex', 'month', 'day', 'search'): + if lookup_type in ('regex', 'iregex', 'month', 'day', 'week_day', 'search'): return [value] elif lookup_type in ('exact', 'gt', 'gte', 'lt', 'lte'): return [self.get_db_prep_value(value)] @@ -490,9 +490,9 @@ class DateField(Field): curry(cls._get_next_or_previous_by_FIELD, field=self, is_next=False)) def get_db_prep_lookup(self, lookup_type, value): - # For "__month" and "__day" lookups, convert the value to a string so - # the database backend always sees a consistent type. - if lookup_type in ('month', 'day'): + # For "__month", "__day", and "__week_day" lookups, convert the value + # to a string so the database backend always sees a consistent type. + if lookup_type in ('month', 'day', 'week_day'): return [force_unicode(value)] return super(DateField, self).get_db_prep_lookup(lookup_type, value) diff --git a/django/db/models/sql/constants.py b/django/db/models/sql/constants.py index e14816c965..63c704fea1 100644 --- a/django/db/models/sql/constants.py +++ b/django/db/models/sql/constants.py @@ -4,7 +4,7 @@ import re QUERY_TERMS = dict([(x, None) for x in ( 'exact', 'iexact', 'contains', 'icontains', 'gt', 'gte', 'lt', 'lte', 'in', 'startswith', 'istartswith', 'endswith', 'iendswith', 'range', 'year', - 'month', 'day', 'isnull', 'search', 'regex', 'iregex', + 'month', 'day', 'week_day', 'isnull', 'search', 'regex', 'iregex', )]) # Size of each "chunk" for get_iterator calls. diff --git a/django/db/models/sql/where.py b/django/db/models/sql/where.py index 8724906a8c..d97112e9f3 100644 --- a/django/db/models/sql/where.py +++ b/django/db/models/sql/where.py @@ -174,9 +174,9 @@ class WhereNode(tree.Node): params) elif lookup_type in ('range', 'year'): return ('%s BETWEEN %%s and %%s' % field_sql, params) - elif lookup_type in ('month', 'day'): - return ('%s = %%s' % connection.ops.date_extract_sql(lookup_type, - field_sql), params) + elif lookup_type in ('month', 'day', 'week_day'): + return ('%s = %%s' % connection.ops.date_extract_sql(lookup_type, field_sql), + params) elif lookup_type == 'isnull': return ('%s IS %sNULL' % (field_sql, (not value_annot and 'NOT ' or '')), ()) |
