2012-05-11 6 views
2

私はrestapiを実装するためにdjango-tastypieを使用しています。私はsenchaをモバイルクライアントとして使用しています。私はいくつかの目的のために応答テキストを操作する必要があります。django tastypie jsonにsuccess = trueを追加する方法

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

成功を送信するために非常に重要であるが、以下のように

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

以下

のように私は=> trueの場合、成功は定義されていないか、それを真実と等しくされていないJSONレスポンスを持っていますフォーム送信エラーとみなされます。 django tastypie jsonにsuccess = trueを追加するには

答えて

1

質問が正しく分かったら、{'success': true}をAPI呼び出しの結果に追加しますか?もしそうなら、あなたはあなたのResourceクラスにdehydrateメソッドをオーバーライドすることができます。すべての要求タイプのためにそれを行う

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

文句を言わないが」、 'GET'のように? – Amyth

関連する問題