Created
April 26, 2015 05:12
-
-
Save beardedeagle/cedb0c8a11904242ff31 to your computer and use it in GitHub Desktop.
dehydrate mixin to allow for field selection in Tastypie
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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