Im sending a POST that creates a new simple Resource (not a ModelResource), and that works.
My question is how do I get back for example the created resource’s bundle property to the ajax response?
That’s the resource example :
class MyResource(Resource):
x = fields.CharField(attribute='x')
y = fields.CharField(attribute='y')
class Meta:
resource_name = 'myresource'
object_class = XYObject
authorization = Authorization()
def obj_create(self, bundle, request=None, **kwargs):
x = bundle.data["x"]
x = bundle.data["y"]
bundle.obj = XYObject(x, y)
return bundle
And this is the POST request
$.ajax({
type: "POST",
url: '/api/v1/myresource/',
contentType: 'application/json',
data: data,
dataType: 'json',
processData: false,
success: function(response)
{
//get my resource here
},
error: function(response){
$("#messages").show('error');
}
});
You can just add
always_return_data = Trueto your Meta. You’ll then get a202with serialized data instead of the normal201.from https://stackoverflow.com/a/10138745/931277
Here are the docs: http://django-tastypie.readthedocs.org/en/latest/resources.html#always-return-data