Skip to content

Commit 4780380

Browse files
committed
fix: refactor superuser creation to use defaults in get_or_create
1 parent b88d05f commit 4780380

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

website/setup/management/commands/safecreatesuperuser.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,19 @@ def handle(self, *args, **options):
3131
options["email"] = os.environ["DJANGO_SUPERUSER_EMAIL"]
3232
options["password"] = os.environ["DJANGO_SUPERUSER_PASSWORD"]
3333

34+
defaults = {
35+
"email": options["email"],
36+
"password": options["password"],
37+
"is_superuser": True,
38+
"is_staff": True,
39+
}
40+
3441
obj, created = User.objects.get_or_create(
3542
username=options["username"],
36-
email=options["email"],
37-
password=options["password"],
38-
is_superuser=True,
39-
is_staff=True,
43+
defaults=defaults,
4044
)
4145

4246
if created:
43-
self.stdout.write(self.style.SUCCESS("Admin user created"))
47+
self.stdout.write(self.style.SUCCESS(f"Superuser created: {obj}"))
4448
else:
45-
self.stdout.write(self.style.SUCCESS("Admin user already exists"))
49+
self.stdout.write(self.style.SUCCESS(f"Superuser already exists: {obj}"))

0 commit comments

Comments
 (0)