Skip to content

Instantly share code, notes, and snippets.

@biomorgoth
biomorgoth / resource_mixin.py
Last active August 29, 2015 14:20
Tastypie Resource Mixin for selecting only a specific set of object fields from DB from a URL query
class FieldSelectMixin(object):
"""
Mixin to allow field selection.
This has to be done in two parts:
1) In model queryset for database selection. This need to be in some code section
where the queryset is ready, but still not evaluated. obj_get_list and obj_get are perfect
for Tastypie GET requests.
2) In full_dehydrate method, to prevent from Tastypie fetching all the fields from the model.
"""
def full_dehydrate(self, bundle, for_list=False):