mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-07-22 14:29:36 +02:00
chore: Improve superuser creation logic
This commit is contained in:
parent
f8338c6754
commit
175a2371b1
1 changed files with 2 additions and 2 deletions
|
@ -19,13 +19,13 @@ python manage.py migrate
|
||||||
# Check for default data
|
# Check for default data
|
||||||
python manage.py worldtravel-seed
|
python manage.py worldtravel-seed
|
||||||
|
|
||||||
# Create superuser if environment variables are set
|
# Create superuser if environment variables are set and there are no users present at all.
|
||||||
if [ -n "$DJANGO_ADMIN_USERNAME" ] && [ -n "$DJANGO_ADMIN_PASSWORD" ]; then
|
if [ -n "$DJANGO_ADMIN_USERNAME" ] && [ -n "$DJANGO_ADMIN_PASSWORD" ]; then
|
||||||
echo "Creating superuser..."
|
echo "Creating superuser..."
|
||||||
python manage.py shell << EOF
|
python manage.py shell << EOF
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
User = get_user_model()
|
User = get_user_model()
|
||||||
if not User.objects.filter(username='$DJANGO_ADMIN_USERNAME').exists():
|
if User.objects.count() == 0:
|
||||||
User.objects.create_superuser('$DJANGO_ADMIN_USERNAME', '$DJANGO_ADMIN_EMAIL', '$DJANGO_ADMIN_PASSWORD')
|
User.objects.create_superuser('$DJANGO_ADMIN_USERNAME', '$DJANGO_ADMIN_EMAIL', '$DJANGO_ADMIN_PASSWORD')
|
||||||
print("Superuser created successfully.")
|
print("Superuser created successfully.")
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue