2019-07-03 15:18:29 +00:00
|
|
|
from django.core.management.base import BaseCommand
|
|
|
|
from django.contrib.auth import get_user_model
|
|
|
|
|
|
|
|
|
|
|
|
class Command(BaseCommand):
|
|
|
|
help = "Creates an admin user non-interactively if it doesn't exist"
|
|
|
|
|
|
|
|
def add_arguments(self, parser):
|
2024-01-27 10:29:16 +00:00
|
|
|
parser.add_argument("--username", help="Admin's username")
|
|
|
|
parser.add_argument("--email", help="Admin's email")
|
|
|
|
parser.add_argument("--password", help="Admin's password")
|
2019-07-03 15:18:29 +00:00
|
|
|
|
|
|
|
def handle(self, *args, **options):
|
|
|
|
User = get_user_model()
|
2024-01-27 10:29:16 +00:00
|
|
|
if not User.objects.filter(username=options["username"]).exists():
|
|
|
|
User.objects.create_superuser(
|
|
|
|
username=options["username"],
|
|
|
|
email=options["email"],
|
|
|
|
password=options["password"],
|
|
|
|
)
|