Skip to content

Instantly share code, notes, and snippets.

@ncole458
Created December 14, 2015 04:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ncole458/69cfc4a26141d9ce55eb to your computer and use it in GitHub Desktop.
Save ncole458/69cfc4a26141d9ce55eb to your computer and use it in GitHub Desktop.
"""
Django REST Framework filtering by comma (used with Ember.js).
Change from the standard ?var=1&var=2 etc.
"""
# GET querystring i.e. ?var=1,2,4,6
get_my_var = self.request.query_params.get('var', None)
if get_my_var:
my_var = get_my_var.split(',')
else:
my_var = None
# Filter using standard __in
queryset = queryset.filter(my_field__in=my_var)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment