Skip to content

Instantly share code, notes, and snippets.

@toastdriven
Created May 18, 2011 03:01
Show Gist options
  • Select an option

  • Save toastdriven/977921 to your computer and use it in GitHub Desktop.

Select an option

Save toastdriven/977921 to your computer and use it in GitHub Desktop.
class SampleResource(ModelResource):
# ... then ...
def dehydrate(self, bundle):
bundle = super(SampleResource, self).dehydrate(bundle)
bundle.data['the_field'] = call_method_that_returns_the_dict()
return bundle
# Or...
from tastypie import fields
class DictField(fields.ApiField):
dehydrated_type = 'dict'
help_text = "A dictionary of data. Ex: {'abc': 123}"
def convert(self, value):
if value is None:
return None
return dict(value)
class SampleResource(ModelResource):
the_field = DictField(attribute='call_method_that_returns_the_dict')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment