Skip to content

Commit

Permalink
Fixed #7448 -- Convert "in" filters to pass in the correct values for…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
malcolmt committed Jul 11, 2008
1 parent 1e00458 commit 7936c0b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
8 changes: 4 additions & 4 deletions django/db/models/fields/__init__.py
Expand Up @@ -554,7 +554,7 @@ def to_python(self, value):
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')
Expand Down Expand Up @@ -641,7 +641,7 @@ def get_db_prep_save(self, value):
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)
Expand Down Expand Up @@ -720,7 +720,7 @@ def get_db_prep_save(self, value):
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)
Expand Down Expand Up @@ -1097,7 +1097,7 @@ def prep(value):
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)
Expand Down
5 changes: 5 additions & 0 deletions tests/regressiontests/queries/models.py
Expand Up @@ -805,5 +805,10 @@ class Related(models.Model):
>>> 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>]
"""}

0 comments on commit 7936c0b

Please sign in to comment.