Resource
新しい単純な(ModelResourceではない)を作成するPOSTを送信しましたが、それは機能します。
bundle
私の質問は、たとえば、作成されたリソースのプロパティを ajax 応答に戻すにはどうすればよいですか?
それがリソースの例です:
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
そして、これが POST リクエストです
$.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');
}
});