Skip to content

Instantly share code, notes, and snippets.

@bohde
Created November 20, 2011 16:49
Show Gist options
  • Select an option

  • Save bohde/1380471 to your computer and use it in GitHub Desktop.

Select an option

Save bohde/1380471 to your computer and use it in GitHub Desktop.
from tastypie import fields
from tastypie.resources import Resource
class TaggedResource(Resource):
tags = fields.ListField() # no attribute declaration on purpose
def dehydrate_tags(self, bundle):
return map(str, bundle.obj.tags.all())
def save_m2m(self, bundle):
tags = bundle.data.get('tags', [])
bundle.obj.tags.set(*tags)
return super(TaggedResource, self).save_m2m(bundle)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment