Django Admin создает суперпользователь
$ python manage.py createsuperuser
Defeated Dog
$ python manage.py createsuperuser
user@host> manage.py shell
>>> from django.contrib.auth.models import User
>>> user=User.objects.create_user('foo', password='bar')
>>> user.is_superuser=True
>>> user.is_staff=True
>>> user.save()
from django.core.management.base import BaseCommand, CommandError
from django.contrib.auth.models import User
class Command(BaseCommand):
def handle(self, *args, **options):
# The magic line
User.objects.create_user(username= 'rmx',
email='superuser@super.com',
password='rmx55',
is_staff=True,
is_active=True,
is_superuser=True
)
$ python manage.py shell
>>> from django.contrib.auth import get_user_model
>>> User = get_user_model()
>>> User.objects.create_superuser('username', 'email', 'password')
<User: username>
>>> exit()