diff --git a/.gitignore b/.gitignore index 739911f..13d15e2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ civicenv -civicProject.code-workspace +civicProject.code-workspace \ No newline at end of file diff --git a/civicfix/.env b/civicfix/.env index e9edc48..6037fc7 100644 --- a/civicfix/.env +++ b/civicfix/.env @@ -4,4 +4,7 @@ CLOUDINARY_CLOUD_NAME="dkxbfoesf" CLOUDINARY_API_KEY="658671916285379" CLOUDINARY_API_SECRET="_CwNDj4L2dE9yH90Ynj7slPlbo0" CLOUDINARY_URL="cloudinary://658671916285379:_CwNDj4L2dE9yH90Ynj7slPlbo0@dkxbfoesf" -DATABASE_URL="postgresql://civicfix_user:YG56PWj9Xj1DvYIKF35TKmIEjrsfis6d@dpg-d2mpapripnbc73f5vaj0-a/civicfix" \ No newline at end of file +DATABASE_URL="postgresql://civicfix_user:YG56PWj9Xj1DvYIKF35TKmIEjrsfis6d@dpg-d2mpapripnbc73f5vaj0-a.oregon-postgres.render.com/civicfix" +SUPERUSER_USERNAME="admin" +SUPERUSER_PASSWORD="82c96bb18606401630ab9d2836325fbd" +SUPERUSER_EMAIL="gokuldevse2001@gmail.com" \ No newline at end of file diff --git a/civicfix/civicfix/__pycache__/settings.cpython-313.pyc b/civicfix/civicfix/__pycache__/settings.cpython-313.pyc index ec3b6ba..5d110c0 100644 Binary files a/civicfix/civicfix/__pycache__/settings.cpython-313.pyc and b/civicfix/civicfix/__pycache__/settings.cpython-313.pyc differ diff --git a/civicfix/core/management/commands/init_admin.py b/civicfix/core/management/commands/init_admin.py new file mode 100644 index 0000000..759fec3 --- /dev/null +++ b/civicfix/core/management/commands/init_admin.py @@ -0,0 +1,22 @@ +from django.core.management.base import BaseCommand +from django.contrib.auth import get_user_model +import os + +class Command(BaseCommand): + help = "Create a superuser if none exists (using env vars)." + + def handle(self, *args, **options): + User = get_user_model() + username = os.environ.get("SUPERUSER_USERNAME") + email = os.environ.get("SUPERUSER_EMAIL") + password = os.environ.get("SUPERUSER_PASSWORD") + + if not username or not password: + self.stdout.write(self.style.WARNING("SUPERUSER_* env vars not set. Skipping.")) + return + + if not User.objects.filter(username=username).exists(): + User.objects.create_superuser(username=username, email=email, password=password) + self.stdout.write(self.style.SUCCESS(f"Superuser '{username}' created.")) + else: + self.stdout.write(self.style.NOTICE(f"Superuser '{username}' already exists."))