fix: Skip default admin@local.host creation during container startup if an admin user already exists

This commit is contained in:
Richard
2026-08-01 12:42:29 +02:00
parent d9280c3078
commit 565b14533c
2 changed files with 36 additions and 30 deletions
@@ -13,6 +13,12 @@ class Command(BaseCommand):
parser.add_argument('--password', type=str, default=os.getenv('ADMIN_PASSWORD', 'adminpassword'), help='Passwort für den Admin') parser.add_argument('--password', type=str, default=os.getenv('ADMIN_PASSWORD', 'adminpassword'), help='Passwort für den Admin')
def handle(self, *args, **options): def handle(self, *args, **options):
has_existing_admin = User.objects.filter(is_superuser=True).exists() or User.objects.filter(is_admin_user=True).exists()
explicit_env_set = bool(os.getenv('ADMIN_USERNAME') or os.getenv('ADMIN_EMAIL'))
if has_existing_admin and not explicit_env_set and not os.getenv('FORCE_CREATE_ADMIN'):
self.stdout.write(self.style.SUCCESS("️ Mindestens ein Admin-Benutzer existiert bereits. Es wurde kein neuer Standard-Admin ('admin@local.host') erstellt."))
else:
username = options['username'] or os.getenv('ADMIN_USERNAME', 'admin') username = options['username'] or os.getenv('ADMIN_USERNAME', 'admin')
email = options['email'] or os.getenv('ADMIN_EMAIL', 'admin@local.host') email = options['email'] or os.getenv('ADMIN_EMAIL', 'admin@local.host')
password = options['password'] or os.getenv('ADMIN_PASSWORD', 'adminpassword') password = options['password'] or os.getenv('ADMIN_PASSWORD', 'adminpassword')