Reputation: 497
I'm new to Django.
I have a simple issue: I need to have the superuser email of the website to send him an email from the admin panel (actually it is for testing if the email is well formated before sending it to registred users).
To get all users, I type:
users = User.objects.all()
How to get the superuser(s)?
superusers = ...
Upvotes: 22
Views: 54546
Reputation: 1330
is_superuser
is a flag on the User model, as you can see in the documentation here:
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')
Upvotes: 51