added superuser support in apps.lyric.admin & new manage.py cmd ensure_superuser; .tests.integrated.test_admin & .test_management_commands green
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
21
src/apps/lyric/management/commands/ensure_superuser.py
Normal file
21
src/apps/lyric/management/commands/ensure_superuser.py
Normal file
@@ -0,0 +1,21 @@
|
||||
import os
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
from apps.lyric.models import User
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "Create a superuser if none exists"
|
||||
|
||||
def handle(self, *args, **options):
|
||||
if User.objects.filter(is_superuser=True).exists():
|
||||
self.stdout.write("Superuser already exists!")
|
||||
return
|
||||
email = os.environ.get('DJANGO_SUPERUSER_EMAIL')
|
||||
password = os.environ.get('DJANGO_SUPERUSER_PASSWORD')
|
||||
if not email or not password:
|
||||
self.stdout.write("Superuser credentials not set!—skipping")
|
||||
return
|
||||
User.objects.create_superuser(email=email, password=password)
|
||||
self.stdout.write("Superuser created!")
|
||||
Reference in New Issue
Block a user