mirror of
https://github.com/Balshgit/different
synced 2025-12-15 18:30:40 +03:00
add command and README.md
This commit is contained in:
19
django_accounts_app/management/commands/create_superuser.py
Normal file
19
django_accounts_app/management/commands/create_superuser.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from django.core.management.base import BaseCommand
|
||||
from server.apps.accounts.models import CustomUser
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
|
||||
def handle(self, *args, **options):
|
||||
if not CustomUser.objects.filter(username='admin').exists():
|
||||
username = 'admin'
|
||||
email = 'admin@admin.ru'
|
||||
password = 'admin'
|
||||
admin = CustomUser.objects.create_superuser(username=username,
|
||||
password=password,
|
||||
email=email)
|
||||
admin.is_active = True
|
||||
admin.is_admin = True
|
||||
admin.save()
|
||||
else:
|
||||
print('Admin accounts can only be initialized if no Accounts exist')
|
||||
Reference in New Issue
Block a user