Created
December 26, 2016 11:40
-
-
Save Brachamul/f41ee36ae2b127b99fdfd1e81d4b9f6e to your computer and use it in GitHub Desktop.
Set an existing user to superuser using Django shell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
python manage.py shell |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.contrib.auth.models import User | |
user = User.objects.get(username="myname") | |
user.is_staff = True | |
user.is_admin = True | |
user.save() |
To get the correct user object, use:
from django.contrib.auth import get_user_model
User = get_user_model()
In one line:
User.objects.filter(pk=1001).update(is_superuser=True, is_staff=True)
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
You can add the following before the
save()
to set the user as superuser :