Skip to content

Instantly share code, notes, and snippets.

@Brachamul
Created December 26, 2016 11:40
Show Gist options
  • Save Brachamul/f41ee36ae2b127b99fdfd1e81d4b9f6e to your computer and use it in GitHub Desktop.
Save Brachamul/f41ee36ae2b127b99fdfd1e81d4b9f6e to your computer and use it in GitHub Desktop.
Set an existing user to superuser using Django shell
python manage.py shell
from django.contrib.auth.models import User
user = User.objects.get(username="myname")
user.is_staff = True
user.is_admin = True
user.save()
@salty-horse
Copy link

To get the correct user object, use:

from django.contrib.auth import get_user_model
User = get_user_model()

@morenopc
Copy link

morenopc commented Jun 4, 2019

In one line:

User.objects.filter(pk=1001).update(is_superuser=True, is_staff=True)

@Vamoss
Copy link

Vamoss commented Feb 28, 2020

I got this error:
AttributeError: Manager isn't available; 'auth.User' has been swapped for 'users.User'

Worked when did this:

from django.contrib.auth import get_user_model
User = get_user_model()
user = User.objects.get(username="myname")
user.is_staff = True
user.is_admin = True
user.is_superuser = True
user.save()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment