Created
July 24, 2014 10:37
-
-
Save bogsio/c1427ee50e57255bd791 to your computer and use it in GitHub Desktop.
TPT3 - adding dehydrate method
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 TodoListResource(ModelResource): | |
| def dehydrate(self, bundle): | |
| items = bundle.obj.items.all() | |
| bundle.data['item_count'] = items.count() | |
| bundle.data['items'] = [i.to_dict() for i in items] | |
| return bundle | |
| class Meta: | |
| authentication = SessionAuthentication() | |
| authorization = AuthorizationByUser() | |
| queryset = TodoList.objects.all() | |
| resource_name = 'list' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment