[Answered ]-Django: list User details and Group for every User-Group (Many-To-Many) relationship in template

1👍

If you use Django’s Group, you access the set of users with:

{% for group in groups %}
  {% for user in group.user_set.all %}
    …
  {% endfor %}
{% endfor %}

You can further boost efficiency by prefetching all the related users with one extra query, so in the view you work with:

groups = Group.objects.prefetch_related('user_set')

Leave a comment