Created
July 11, 2012 01:30
-
-
Save bohde/3087345 to your computer and use it in GitHub Desktop.
An example conditional full field
This file contains hidden or 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
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