Django - Get a list of users of a certain group

To get a list of users of a certain group (let's call it 'MyGroup'):

from django.contrib.auth import User, Group

users = User.objects.filter(groups=Group.objects.get(name='MyGroup'))

or:

users = User.objects.filter(groups__name__in=['MyGroup'])

Comments