简体   繁体   中英

How to append success=true on django tastypie json

I am using django-tastypie to implement restapi, i am using sencha as a mobile client . I need to manipulate the response text for some purpose.

Like below

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();
        //});
    }
});

I have json response as follows

{"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"}]}

It is very important to send success => true If, success is not defined or not equal to true then it will be considered as a form submit error. How to append success=true on django tastypie json

If I understand your question correctly, you want to append {'success': true} to the result of API calls, correct? If so, you can override the dehydrate method on your Resource class:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM