summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2008-07-11 09:00:35 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2008-07-11 09:00:35 +0000
commit7936c0b9173d5bde02bfb2dd8722733d4c821daf (patch)
tree5e253d7282b648eff5f4a0cde9e85f27ee8b68df
parent1e00458521b81bc86883ce938ea689b799bfd928 (diff)
Fixed #7448 -- Convert "in" filters to pass in the correct values for datetimes
and similar complex objects. Based on patches from cgrady and alexkosholev. Refs #7707. git-svn-id: http://code.djangoproject.com/svn/django/trunk@7883 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/db/models/fields/__init__.py8
-rw-r--r--tests/regressiontests/queries/models.py5
2 files changed, 9 insertions, 4 deletions
diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py
index a97adef474..28111d86e1 100644
--- a/django/db/models/fields/__init__.py
+++ b/django/db/models/fields/__init__.py
@@ -554,7 +554,7 @@ class DateField(Field):
raise validators.ValidationError, _('Enter a valid date in YYYY-MM-DD format.')
def get_db_prep_lookup(self, lookup_type, value):
- if lookup_type == 'range':
+ if lookup_type in ('range', 'in'):
value = [smart_unicode(v) for v in value]
elif lookup_type in ('exact', 'gt', 'gte', 'lt', 'lte') and hasattr(value, 'strftime'):
value = value.strftime('%Y-%m-%d')
@@ -641,7 +641,7 @@ class DateTimeField(DateField):
return Field.get_db_prep_save(self, value)
def get_db_prep_lookup(self, lookup_type, value):
- if lookup_type == 'range':
+ if lookup_type in ('range', 'in'):
value = [smart_unicode(v) for v in value]
else:
value = smart_unicode(value)
@@ -720,7 +720,7 @@ class DecimalField(Field):
return super(DecimalField, self).get_db_prep_save(value)
def get_db_prep_lookup(self, lookup_type, value):
- if lookup_type == 'range':
+ if lookup_type in ('range', 'in'):
value = [self._format(v) for v in value]
else:
value = self._format(value)
@@ -1097,7 +1097,7 @@ class TimeField(Field):
return smart_unicode(value)
else:
prep = smart_unicode
- if lookup_type == 'range':
+ if lookup_type in ('range', 'in'):
value = [prep(v) for v in value]
else:
value = prep(value)
diff --git a/tests/regressiontests/queries/models.py b/tests/regressiontests/queries/models.py
index 566411e513..272e28ff84 100644
--- a/tests/regressiontests/queries/models.py
+++ b/tests/regressiontests/queries/models.py
@@ -805,5 +805,10 @@ Bug #7371
>>> Related.objects.order_by('custom')
[]
+Bug #7448, #7707 -- Complex objects should be converted to strings before being
+used in lookups.
+>>> Item.objects.filter(created__in=[time1, time2])
+[<Item: one>, <Item: two>]
+
"""}