Skip to content

Instantly share code, notes, and snippets.

@zoidyzoidzoid
Created June 24, 2015 09:51
Show Gist options
  • Save zoidyzoidzoid/9ea0e4feb62a45acffee to your computer and use it in GitHub Desktop.
Save zoidyzoidzoid/9ea0e4feb62a45acffee to your computer and use it in GitHub Desktop.
import django_filters
class CommaSeparatedValueFilter(django_filters.CharFilter):
"""Accept comma separated string as value and convert it to list.
It's useful for __in lookups.
"""
def filter(self, qs, value):
if value:
value = value.split(',')
return super(CommaSeparatedValueFilter, self).filter(qs, value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment