groups = request.user.groups.all()
Using the above command, I am getting only the groups of a particular user. But I would like to get all the group names which are available in Django admin. Is there any way to do so?
groups = request.user.groups.all()
Using the above command, I am getting only the groups of a particular user. But I would like to get all the group names which are available in Django admin. Is there any way to do so?
You can access the groups by importing them.
from django.contrib.auth.models import Group
groups = Group.objects.all().values_list('name', flat=True)
borrowed from: Django: How to get the list of the usergroups and use that list (dictionary) as a choice options for a model field?