[Answer]-Creating related records in a single POST request

1👍

Just from playing around with it very, very quickly (and I’m new to tastypie so take this with a grain of salt) – I think you can do this by overriding the obj_create() method inside your resource. Something like this:

class SomeResource(ModelResource):
    class Meta:
        # yadda yadda

    def obj_create(self, bundle, request, **kwargs):
        print "hey we're in object create"
        # do something with bundle.data, this will have your songs in it
        return super(SomeResource, self).obj_create(bundle, request, **kwargs)

0👍

You want to do something like this:

curl --dump-header - -H "Content-Type: application/json" -X POST --data '{"name":"playlist_name", "field2":"value2", "song": ["/api/v1/song/1/"]}' http://localhost:8000/api/v1/playlist/

Good luck!

👤Erik

Leave a comment