Tastypie - Nested Resource field not found

心已入冬 提交于 2019-11-30 20:22:10

The 'video' field has was given data that was not a URI, not a dictionary-alike and does not have a 'pk' attribute: 21.

So, this means that the integer 21 does't meet the requirements for that field, it also give a vague hint of what will meet the requirements.

first, you can send in the URI for the record, this is probably the most correct way as URIs are really unique while pk's are not.

{"video":"/api/v1/video/21","text":"sadasds"} 

or, you can send in an dictionary-alike object with the pk field set.

{"video":{'pk':21},"text":"sadasds"} 

The reason it works when you comment out the ForeignKey field is because then tastypie treats it as a IntegerField, which can be referenced by a plain integer.

This had me stunted for a while to, hope it helps!

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