Django Tastypie not Updating Resource with ManyToManyField

给你一囗甜甜゛ 提交于 2019-11-29 08:48:50

The problem turned out to be the validation method. Using FormValidation means that a uri like /api/v1/organizations/1/ won't validate as a ForeignKey for the Django ORM. Using a custom validation instead fixes the issue.

Many Bothans died to bring us this information.

Looks like you set both ManyToManyField in DeviceResource and ForiegnKey in OrganizationResource to be full=True.

So when doing a PUT Tastypie expects a full object given to it or at the very least a "blank" object with resource_uri for it.

Try sending in object itself with resource_uri specified instead of just the uri i.e.: {"resource_uri" : "/api/v1/organizations/1/"} instead of "/api/v1/organizations/1/"

curl --dump-header - -H "Content-Type: application/json" -X PUT --data '{"uuid":"blah","pass_token":"blah","favorites": [{"resource_uri" : "/api/v1/organizations/1/"}]}' http://localhost:8000/api/v1/devices/2/
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!