如何最好地处理 API 中的 M2M 关系
我正忙于使用 django 和 tastypie 创建 API。我对如何管理外键关系更新有点茫然。我有以多对多方式相关的用户和组对象。 Tastypie 为我提供了在每次更新中更新相关集的功能,即当我更新一个组时,我必须提供整个相应的用户集。
理想情况下,我希望有单独的功能来添加和删除关系。考虑到 1 个组有 1000 个用户,我只想删除 2 个用户。我希望访问一个 url 并提供需要删除的 2 个用户,而不是加载包含 1000 个用户的组对象,删除 2 个用户,然后将 998 个用户连同组详细信息一起发送回来。
处理这种情况的正确设计方法是什么?考虑到我对 tastypie 的使用,我怎样才能在实践中最好地实现这一点?
I'm busy creating an API using django with tastypie. I'm at a bit of a loss on how I should manage the foreign key relationship updates. I have User and Group objects related in a many-to-many fashion. Tastypie offers functionality for me to update the related set within each update, ie when I update a group I must supply the whole corresponding user set.
Ideally I'd like to have separate functionality to add and remove relationships. Consider the fact that 1 group has 1000 users, and I simply want to remove 2 users. I would love to access a url and give the 2 users that need to be deleted instead of loading the group object with its 1000 users, removing 2, then sending 998 users back along with the group details.
What is the correct design method to handle this case? Considering my use of tastypie, how can I best implement this practically?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论