gealogiuya
This commit is contained in:
25
apps/shared/management/commands/createadmin.py
Normal file
25
apps/shared/management/commands/createadmin.py
Normal file
@@ -0,0 +1,25 @@
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
def handle(self, *args, **options):
|
||||
user = get_user_model()
|
||||
self.create_superuser(user, "jahongir", "jahongirhakimjonov@gmail.com", "1253")
|
||||
self.create_superuser(
|
||||
user, "Jahongir", "jahongirhakimjonov@gmail.com", "20030307mart"
|
||||
)
|
||||
self.create_superuser(
|
||||
user, "998330078587", "jahongirhakimjonov@gmail.com", "20030307mart"
|
||||
)
|
||||
|
||||
def create_superuser(self, user, username, email, password):
|
||||
if not user.objects.filter(username=username).exists():
|
||||
user.objects.create_superuser(username, email, password)
|
||||
self.stdout.write(
|
||||
self.style.SUCCESS(f"Superuser {username} created successfully.")
|
||||
)
|
||||
else:
|
||||
self.stdout.write(
|
||||
self.style.SUCCESS(f"Superuser {username} already exists.")
|
||||
)
|
||||
Reference in New Issue
Block a user