1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-08-05 13:15:18 +02:00

Merge pull request #228 from seanmorley15/development

chore: Improve superuser creation logic
This commit is contained in:
Sean Morley 2024-08-17 08:00:20 -04:00 committed by GitHub
commit 816e0c08fd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -19,13 +19,13 @@ python manage.py migrate
# Check for default data
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
echo "Creating superuser..."
python manage.py shell << EOF
from django.contrib.auth import 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')
print("Superuser created successfully.")
else: