add command and README.md

This commit is contained in:
2021-10-25 22:40:08 +03:00
parent 3f14070560
commit bef1e8a9f1
2 changed files with 80 additions and 0 deletions

View 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')