Skip to content

Commit

Permalink
Added splitting on commas for range and in filters.
Browse files Browse the repository at this point in the history
  • Loading branch information
tmc authored and toastdriven committed Mar 25, 2011
1 parent 4c602ce commit 5c042f9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tastypie/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -1349,6 +1349,10 @@ def build_filters(self, filters=None):
elif value in ('nil', 'none', 'None', None):
value = None

# Split on ',' if not empty string and either an in or range filter.
if filter_type in ('in', 'range') and len(value):
value = value.split(',')

db_field_name = LOOKUP_SEP.join(lookup_bits)
qs_filter = "%s%s%s" % (db_field_name, LOOKUP_SEP, filter_type)
qs_filters[qs_filter] = value
Expand Down
5 changes: 5 additions & 0 deletions tests/core/tests/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,11 @@ def test_build_filters(self):
# Valid simple (explicit ``__exact``).
self.assertEqual(resource.build_filters(filters={'title__exact': 'Hello world.'}), {'title__exact': 'Hello world.'})

# Valid in.
self.assertEqual(resource.build_filters(filters={'title__in': ''}), {'title__in': ''})
self.assertEqual(resource.build_filters(filters={'title__in': 'foo'}), {'title__in': ['foo']})
self.assertEqual(resource.build_filters(filters={'title__in': 'foo,bar'}), {'title__in': ['foo', 'bar']})

# Valid simple (non-``__exact``).
self.assertEqual(resource.build_filters(filters={'content__startswith': 'Hello'}), {'content__startswith': 'Hello'})

Expand Down

0 comments on commit 5c042f9

Please sign in to comment.