如何在Python Eve中更新列表data_relation

时间:2014-11-07 22:53:33

标签: python eve datarelation

我有一个模型'用户'及其模式,其中包含一对多关系回馈给用户:

'followers': {
    'type': 'list',
    'schema': {
            'type': 'objectid',
            'data_relation': {
                    'resource': 'users'
            }
    }
},

我正在尝试更新关注者列表。我尝试使用'followers'键和objectids列表向 / users / 545c7dccb505970bbf0e5ad1 端点发送PATCH请求,但它不起作用。还尝试向 / users / 545c7dccb505970bbf0e5ad1 / followers / 发送PUT请求,但没有运气。

那么如何使用Python Eve REST API将对象添加到此列表中?

GET /users/545c7dccb505970bbf0e5ad1/
{
    "_updated": "Fri, 07 Nov 2014 08:07:40 GMT",
    "public_key": "test",
    "_etag": "256d6da738a0f39929d40d1c868e1f67661460be",
    "_links": {
        "self": {
            "href": "/users/545c7dccb505970bbf0e5ad1",
            "title": "User"
        },
        "parent": {
            "href": "",
            "title": "home"
        },
        "collection": {
            "href": "/users",
            "title": "users"
        }
    },
    "active": false,
    "_created": "Fri, 07 Nov 2014 08:07:40 GMT",
    "_id": "545c7dccb505970bbf0e5ad1"
}

PATCH /users/545c7dccb505970bbf0e5ad1
{
    "_status": "ERR",
    "_error": {
        "message": "You don't have the permission to access the requested resource. It is either read-protected or not readable by the server.",
        "code": 403
    }
}

PUT /users/545c7dccb505970bbf0e5ad1/followers
{
    "_status": "ERR",
    "_error": {
        "message": "The requested URL was not found on the server.  If you entered the URL manually please check your spelling and try again.",
        "code": 404
    }
}

1 个答案:

答案 0 :(得分:2)

doesn't work非常广泛...但是在猜测时,您需要发送服务器在获取或创建用户时返回的_etag令牌...这是防止更新日期模型