Skip to content

Instantly share code, notes, and snippets.

@dmarchuk
Forked from zoidyzoidzoid/filters.py
Created April 20, 2020 00:25
Show Gist options
  • Save dmarchuk/675a08fc99299daa5ad47cfadff33793 to your computer and use it in GitHub Desktop.
Save dmarchuk/675a08fc99299daa5ad47cfadff33793 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