Reputation: 79
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
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