如何在django tastypie json上追加成功= true

时间:2012-05-11 15:22:50

标签: python django extjs tastypie

我正在使用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,则将其视为表单提交错误。 如何在django tastypie json上追加成功= true

1 个答案:

答案 0 :(得分:1)

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

def dehydrate(self, bundle):
    bundle.data['success'] = True
    return bundle