'How to get all the group names irrespective of users in django?

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?



Solution 1:[1]

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?

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Hrafn Malmquist