[Django]-How to get superuser details in Django?

46👍

is_superuser is a flag on the User model, as you can see in the documentation here:

https://docs.djangoproject.com/en/1.11/ref/contrib/auth/#django.contrib.auth.models.User.is_superuser

So to get the superusers, you would do:

from django.contrib.auth.models import User


superusers = User.objects.filter(is_superuser=True)

And if you directly want to get their emails, you could do:

superusers_emails = User.objects.filter(is_superuser=True).values_list('email')

Leave a comment