Skip to content

Instantly share code, notes, and snippets.

@bohde
Created July 11, 2012 01:30
Show Gist options
  • Save bohde/3087345 to your computer and use it in GitHub Desktop.
Save bohde/3087345 to your computer and use it in GitHub Desktop.
An example conditional full field
from tastypie.fields import ToManyField
class ConditionalRelatedField(ToManyField):
truthy = set('1', 'true', 'yes')
def dehydrate_related(self, bundle, related_resource):
full = bundle.request.GET.get('include_entitites', '').lower()
if full not in self.truthy:
return related_resource.get_resource_uri(bundle)
else:
bundle = related_resource.build_bundle(obj=related_resource.instance, request=bundle.request)
return related_resource.full_dehydrate(bundle)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment