2

我正在使用 django-tastypie 来实现 restapi,我正在使用 sencha 作为移动客户端。我需要出于某种目的操纵响应文本。

像下面

form.submit({
    success: function() {
        // The callback function is run when the user taps the 'ok' button
        form.reset();

        //Ext.Msg.alert('Thank You', 'Your message has been received', function() {
        //  form.reset();
        //});
    }
});

我有json响应如下

{"meta": {"limit": 20, "next": null, "offset": 0, "previous": null, "total_count": 13},       
 "objects": [{"body": "This will prbbly be my lst edited  post.", "id": 1,
 "pub_date":  "2011-05-22", "resource_uri": "/api/v1/entry/1/", "slug": "another-post", 
 "title": "Another Post"}, {"body": "This will prbbly be my lst post.", "id": 2, 
 "pub_date": "2011-05-22", "resource_uri": "/api/v1/entry/2/", "slug": "another-post", 
 "title": "Another Post"}, {"body": "This will prbbly be my lst edited  post"}]}

发送成功 => true 非常重要 如果未定义成功或不等于 true 则将视为表单提交错误。如何在 django tastepie json 上附加 success=true

4

1 回答 1

1

如果我正确理解您的问题,您想附加{'success': true}到 API 调用的结果,对吗?如果是这样,您可以覆盖类的脱水方法Resource

def dehydrate(self, bundle):
    bundle.data['success'] = True
    return bundle
于 2012-05-11T19:24:01.127 回答