django-piston:如何将实体字段添加到manyToMany相关的实体字段?

时间:2011-06-09 22:56:53

标签: django json django-piston

我有两个实体:Post和Tag,有一个名为'tagged'的ManyToMany关系

我需要做的是,为了解析在特定客户端上返回的json,输出字段是通过将一个字段'postID'(当前Post的pk字段)添加到与该帖子相关的Tag。

所以,我现在的输出是:

{
    "post": {
        "name": "Dummy name", 
        "pk": 1,
        "tags": [
            {
                "id": 2, 
                "name": "Patio"
            }, 
            {
                "id": 3, 
                "name": "Roof"
            }
        ], 
        "ref": "709230056"
    }
}, 

但它应该是:

{
    "post": {
        "name": "Dummy name",
        "pk": 1,
        "tags": [
            {
                "id": 2, 
                "name": "Patio",
                "postID": 1,


            }, 
            {
                "id": 3, 
                "name": "Roof"
                "postID": 1,
            }
        ], 
        "ref": "709230056"
    }
}, 

我已经尝试使用我的处理程序的字段,但没有成功:(

怎么做? 感谢

0 个答案:

没有答案