1
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?

Andrew
  • 1,238
  • 3
  • 13
  • 28

1 Answers1

0

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?

Hrafn Malmquist
  • 432
  • 4
  • 10