Skip to content

Commit 9f11821

Browse files
authored
Merge pull request #167 from cmu-delphi/add-custom-createsuperuser-command
Added custom createsuperuser command
2 parents 7b88f25 + a223d46 commit 9f11821

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

src/base/management/__init__.py

Whitespace-only changes.

src/base/management/commands/__init__.py

Whitespace-only changes.
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import os
2+
from django.core.management.base import BaseCommand
3+
from django.contrib.auth.models import User
4+
5+
6+
ADMIN_USERNAME = os.environ.get("ADMIN_USERNAME", "admin") # Default username
7+
ADMIN_EMAIL = os.environ.get("ADMIN_EMAIL", "[email protected]") # Default email
8+
ADMIN_PASSWORD = os.environ.get("ADMIN_PASSWORD", "admin123") # Default password
9+
10+
11+
class Command(BaseCommand):
12+
help = "Automatically creates a superuser"
13+
14+
def handle(self, *args, **kwargs):
15+
if not User.objects.filter(username=ADMIN_USERNAME).exists():
16+
User.objects.create_superuser(ADMIN_USERNAME, ADMIN_EMAIL, ADMIN_PASSWORD)
17+
self.stdout.write(self.style.SUCCESS("Superuser created successfully"))
18+
else:
19+
self.stdout.write(self.style.WARNING("Superuser already exists"))

0 commit comments

Comments
 (0)