1👍
✅
After some research, I managed to do what I wanted and thought I’d share it. I was able to do it using django-extensions
. I made a python script
# create_admin.py
import os
if "ADMIN_USER" in os.environ and "ADMIN_PASSWORD" in os.environ:
from django.contrib.auth.models import User
user=User.objects.create_user(os.environ['ADMIN_USER'], password=os.environ['ADMIN_PASSWORD'])
user.is_superuser=True
user.is_staff=True
user.save()
and changed the scripts part of my app.json
"scripts": {
"postdeploy": "sh -c 'python manage.py syncdb --noinput; python manage.py migrate --noinput; python manage.py runscript create_admin'"
}
make sure you read django-extensions
docs for more information on where to place the scripts and how to python manage.py runscript
.
IMPORTANT: you may want to go to herkou’s configs page and remove the environment variables after you run the script.
Source:stackexchange.com