如何在Python Eve中更新列表data_relation [英] How do I update a list data_relation in Python Eve

查看:116
本文介绍了如何在Python Eve中更新列表data_relation的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用户"模型和一个模式,其中包括一个与用户的一对多关系:

I have a model 'users' and a schema for it, which includes a one-to-many relation back to users:

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

我正在尝试更新关注者列表.我尝试将PATCH请求发送给/users/545c7dccb505970bbf0e5ad1 终结点,该请求带有'followers'键和一个objectid列表,但是它不起作用.还尝试将PUT请求发送到/users/545c7dccb505970bbf0e5ad1/followers/,但没有成功.

I am trying to update the list of followers. I tried sending PATCH request to the /users/545c7dccb505970bbf0e5ad1 endpoint with a 'followers' key and a list of objectids but it doesn't work. Also tried sending a PUT request to /users/545c7dccb505970bbf0e5ad1/followers/ but no luck.

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

So how do I add an object to this list with 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
    }
}

推荐答案

doesn't work非常广泛...但是,您可能需要将_etag令牌发送给获取或创建用户时返回的服务器. .这是必需的,以防止从过时的模型进行更新

doesn't work is awfully broad... however at a guess you need to send your _etag token the server returned when fetching or creating the user... this is required to prevent updating from an out of date model

这篇关于如何在Python Eve中更新列表data_relation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆