Django: removing item from many-to-many relation more efficiently

吃可爱长大的小学妹 提交于 2019-12-04 16:07:07

Yes. You can access the underlying M2M model using the through attribute, and then use that model to do a delete in one query.

Book.readers.through.objects.filter(book_id__in=[1, 2, 3, 4, 5], 
                                    user_id=foo_user)
                            .delete()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!