how to get list of objects involving many to many relation in django

别等时光非礼了梦想. 提交于 2019-12-04 02:08:33

Actually, you have already accomplished it (Almost):

committee_relations = CommitteeRole.objects.filter(user=request.user).values_list('committee__pk', flat=True)
item_list = Item.objects.filter(committees__in=committee_relations)

And, if you are looking for a single query, you can try this:

items = Item.objects.filter(customer__committees__committeerole__user=request.user)

Documentation here and here

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