[Django]-How to get all users of a group in Django?

90👍

The following query solved my problem.

User.objects.filter(groups__name='Staff')

Thanks to @SardorbekImomaliev for figuring it out.

10👍

This query allows you to find users by group id rather than by group name:

group = Group.objects.get(id=group_id)
users = group.user_set.all()

Here’s a query that lets you search by group name:

users = User.objects.filter(groups_name='group_name')

Leave a comment