Skip to content

Instantly share code, notes, and snippets.

@beardedeagle
Created April 26, 2015 05:12
Show Gist options
  • Save beardedeagle/cedb0c8a11904242ff31 to your computer and use it in GitHub Desktop.
Save beardedeagle/cedb0c8a11904242ff31 to your computer and use it in GitHub Desktop.
dehydrate mixin to allow for field selection in Tastypie
class fieldSelectMixin(object):
"""
Mixin to allow field selection, dehydrate method.
"""
def dehydrate(self, bundle):
selectedFields = bundle.request.GET.get('fields')
if selectedFields:
selectedFields = selectedFields.split(',')
removedFields = [field for field in bundle.data.keys() if field not in selectedFields]
for field in removedFields:
del bundle.data[field]
return bundle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment