1
0
mirror of https://github.com/django/django.git synced 2025-11-07 07:15:35 +00:00

Fixed #8510 -- Allow both strings (mostly for the admin) and integers to be

used in "month" and "day" filters on date/datetime fields. Without this commit,
SQLite behaved inconsistently after [8494].


git-svn-id: http://code.djangoproject.com/svn/django/trunk@8526 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Malcolm Tredinnick
2008-08-25 03:17:06 +00:00
parent 6d6fb392b4
commit d535edb9da
2 changed files with 20 additions and 5 deletions

View File

@@ -568,6 +568,13 @@ class DateField(Field):
else:
return self.editable or self.auto_now or self.auto_now_add
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'):
return [force_unicode(value)]
return super(DateField, self).get_db_prep_lookup(lookup_type, value)
def get_db_prep_value(self, value):
# Casts dates into the format expected by the backend
return connection.ops.value_to_db_date(self.to_python(value))