18👍
✅
One solution is to use 2 queries.
You can use the reverse relationships to query all Group
s that an Item
in your items
points to.
groups = groups.objects.filter(item__in=items).distinct().values_list('name', flat=True)
Source:stackexchange.com