django-tastypie and many to many “through” relationships

青春壹個敷衍的年華 提交于 2019-11-30 20:40:39
Yeo

You mentioned:

I may have found the error myself. ToManyField should be directed toward Ingredient and not RecipeIngredient. I'll see if this does the job.

There's a better approach though [Tastypie M2M](http://blog.eugene-yeo.in/django-tastypie-manytomany-through.html) (old blog is offline: https://github.com/9gix/eugene-yeo.in/blob/master/content/web/django-tastiepie-m2m.rst)

In short summary, Instead of ToManyField to Ingredients, I use ToManyField toward the ThroughModel. And customize the attribute kwargs to be a callback function that return the ThroughModel Queryset.

Update (2014 Apr)

This answer is made long ago. Not sure if it is still useful.

I had the same issue as you. To solve it, I simply just removed the ToMany field (like in RecipeResource) from the API. This worked for us because the model still had the the manytomany field (just not the API), and you could still query the relation by querying the intermediate model instead.

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