Skip to content

Instantly share code, notes, and snippets.

@marteinn
Last active August 29, 2015 14:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save marteinn/b4a88868f0366904de0d to your computer and use it in GitHub Desktop.
Save marteinn/b4a88868f0366904de0d to your computer and use it in GitHub Desktop.
How to use Tastypies resource serialization outside the api
"""
Credit to the parker library (https://github.com/coxmediagroup/parker/) and their TastyPieHandler.
"""
req = HttpRequest()
resource = YourResource()
bundle = resource.build_bundle(obj=your_model)
bundle = resource.full_dehydrate(bundle)
bundle = resource.alter_detail_data_to_serialize(req, bundle)
json_string = resource.serialize(req, bundle, 'application/json')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment