Oct 23

Django - avoiding typing password for superuser

When developing Django applications I call some kind of flush.py script innumerable times to recreate and sync database, import some data and create super user. It looks like:

#!/usr/bin/env bash
mysql -u root -e "DROP DATABASE secret_project_db;" 
mysql -u root -e "CREATE DATABASE secret_project_db CHARACTER SET='utf8';" 
./manage.py syncdb --noinput
./manage.py loaddata app/fixtures/*
./manage.py createsuperuser --username=admin --email=admin@example.com

It does the job quick but the thing that really annoy me is entering password and password confirmation each time over and over again. In looking for a quick way to reduce typing this is what I have now instead of last line in previous example:

echo "from django.contrib.auth.models import User; User.objects.create_superuser('admin', 'admin@example.com', 'pass')" | ./manage.py shell

Hope it will save you some typing too, if anyone has better idea then to call shell let me know in the comments.