Skip to content

Instantly share code, notes, and snippets.

@bogsio
Created July 24, 2014 10:37
Show Gist options
  • Select an option

  • Save bogsio/c1427ee50e57255bd791 to your computer and use it in GitHub Desktop.

Select an option

Save bogsio/c1427ee50e57255bd791 to your computer and use it in GitHub Desktop.
TPT3 - adding dehydrate method
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