75
Yes, but you’ll do it through the Django shell:
python manage.py shell
Then fetch your user from the database:
from django.contrib.auth.models import User
user = User.objects.get(username="myname")
user.is_staff = True
user.is_admin = True
user.save()
Exit the shell, and that user will now be an admin user.
You can also add the line
user.is_superuser = True
before calling user.save()
if you want or need this user to be a superuser and have all the available permissions.
12
The accepted answer generated an error on Django 3:
AttributeError: Manager isn't available; 'auth.User' has been swapped for 'users.User'
From Django shell:
python manage.py shell
Run 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()
- [Django]-Django accessing ManyToMany fields from post_save signal
- [Django]-Login() in Django testing framework
- [Django]-Trying to migrate in Django 1.9 — strange SQL error "django.db.utils.OperationalError: near ")": syntax error"
Source:stackexchange.com