Ho una configurazione molto simile alla persona in questa domanda: How do I update a list data_relation in Python Eve con una risorsa utenti e una sub-risorsa di amici di tipo lista.Come aggiungere a un elenco digitare in Python Eve senza sostituire i vecchi valori
users = {
…
‘friends’: {
'type': 'list’,
'schema': {
'type': 'objectid’,
'data_relation': {
'resource': 'users’
}
}
}
},
Tuttavia, quando provo ad aggiungere un nuovo valore alla lista amici, gli altri valori nella lista vengono sostituiti dal nuovo valore. Come posso aggiungere un singolo valore alla lista e mantenere i vecchi valori?
GET /users/5522987f893e3902048c55ff
{
"_updated": "Wed, 15 Apr 2015 17:22:07 GMT",
"_created": "Mon, 06 Apr 2015 14:30:23 GMT",
"_id": "5522987f893e3902048c55ff",
"friends": [
"552e9eb0893e391063045edc"
]
}
PATCH /users/5522987f893e3902048c55ff
{"friends": [“550f288d893e390204b0a5ac”]}
RESPONSE:
{
"_updated": "Wed, 15 Apr 2015 19:38:06 GMT",
"_created": "Mon, 06 Apr 2015 14:30:23 GMT",
"_status": "OK",
"_id": "5522987f893e3902048c55ff"
}
GET /users/5522987f893e3902048c55ff
{
"_updated": "Wed, 15 Apr 2015 19:38:06 GMT",
"_created": "Mon, 06 Apr 2015 14:30:23 GMT",
"_id": "5522987f893e3902048c55ff",
"friends": [
"550f288d893e390204b0a5ac"
]
}
Ho anche provato PUT, ma sostituisce anche l'elenco con il nuovo valore.
EDIT: ho appena provato ad utilizzare POST.
POST /users/5522987f893e3902048c55ff/friends
{"552e9eb0893e391063045edc"}
RESPONSE:
{
"_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
}
}
E
POST /users/5522987f893e3902048c55ff
{"friends": ["552e9eb0893e391063045edc"]}
RESPONSE:
{
"_status": "ERR",
"_error": {
"message": "The method is not allowed for the requested URL.",
"code": 405
}
}
È necessario utilizzare un POST per aggiungere un nuovo elemento ... –
Non utilizzare mai MS Word per modificare programmi o dati. Hai alcune ellissi e virgolette che vengono automaticamente corrette. –
Grazie per la rapida risposta! Ho appena modificato la mia domanda dopo aver provato a pubblicare un nuovo amico. –