Created
May 18, 2011 03:01
-
-
Save toastdriven/977921 to your computer and use it in GitHub Desktop.
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
| 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