How do I update a list data_relation in Python Eve

て烟熏妆下的殇ゞ 提交于 2019-12-12 04:54:14

问题


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'
            }
    }
},

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.

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
    }
}

回答1:


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



来源:https://stackoverflow.com/questions/26811438/how-do-i-update-a-list-data-relation-in-python-eve

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!