[Fixed]-Get all related many-to-many objects from a Django QuerySet

18👍

One solution is to use 2 queries.

You can use the reverse relationships to query all Groups that an Item in your items points to.

groups = groups.objects.filter(item__in=items).distinct().values_list('name', flat=True)

Leave a comment