[Django]-Django user group from request user

3👍

As MattH pointed out here https://stackoverflow.com/a/2245908/5936450 you could use the following (slightly altered for your example):

user_group = request.user.groups.values_list('name', flat=True)

1👍

You have first to query all groups of a specific user using this

request.user.groups.all()

it will return a list of groups for that user

then for a getting a specific one, suppose it is the first element in the list

group = request.user.groups.all()[0].name

Leave a comment