From b45660fbcf5dd22188354bfa0193845e568bda53 Mon Sep 17 00:00:00 2001 From: Mole Shang <135e2@135e2.dev> Date: Sat, 24 Jan 2026 19:47:41 +0800 Subject: initial commit --- store/migrations/0002_create_superuser.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 store/migrations/0002_create_superuser.py (limited to 'store/migrations/0002_create_superuser.py') diff --git a/store/migrations/0002_create_superuser.py b/store/migrations/0002_create_superuser.py new file mode 100644 index 0000000..4f322d6 --- /dev/null +++ b/store/migrations/0002_create_superuser.py @@ -0,0 +1,26 @@ +from django.db import migrations +import os + +def create_superuser(apps, schema_editor): + User = apps.get_model('store', 'User') + db_alias = schema_editor.connection.alias + + if not User.objects.using(db_alias).filter(username='admin').exists(): + User.objects.create_superuser( + username=os.environ.get('DJANGO_SUPERUSER_USERNAME', 'admin'), + email=os.environ.get('DJANGO_SUPERUSER_EMAIL', 'admin@example.com'), + password=os.environ.get('DJANGO_SUPERUSER_PASSWORD', 'admin'), + is_staff=True, + is_superuser=True, + roles=['user', 'admin'] + ) + +class Migration(migrations.Migration): + + dependencies = [ + ('store', '0001_initial'), + ] + + operations = [ + migrations.RunPython(create_superuser, migrations.RunPython.noop), + ] -- cgit v1.2.3