user9673470
user9673470

Reputation: 79

How can I get superuser's information?

I am making Django app.I want to use superuser's data in the codes. I registered name&email&password.Usually User's data can be gotten like

user = User.objects.get(id=1)
name = user.name

but how can I get superuser's data?

Upvotes: 0

Views: 961

Answers (1)

solarissmoke
solarissmoke

Reputation: 31514

You can filter superusers like this:

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

You can have more than one superuser on a site, so this query will give you a queryset of superusers, not just one (you could do .get() if there was only one, but this would give you an error if there was more than one).

You can then inspect each superuser by iterating over them:

for user in superusers:
    print(user)

Upvotes: 1

Related Questions