### Handy functions if you have a single folder that contains a directory for each project
# shortcut commands for Django
### --- Don't use a trailing slash when defining you path
DJANGOPATH="/path/to/projects/container"
runserver()
{
if [ $1 = "--help" ]; then
echo "Usage: runserver PROJECT_NAME";
else
cd ${DJANGOPATH}/$1; python manage.py runserver; cd ~;
fi
}
sql()
{
if [ $1 = "--help" ]; then
echo "Usage: sql PROJECT_NAME APP_NAME";
else
cd ${DJANGOPATH}/$1; python manage.py sql $2; cd ~;
fi
}
startproject()
{
if [ $1 = "--help" ]; then
echo "Usage: startproject PROJECT_NAME";
else
cd {$DJANGOPATH}; django-admin startproject $1 project; cd $1;
fi
}
startapp()
{
if [ $1 = "--help" ]; then
echo "Usage: startapp [ -p ] APP_NAME PROJECT_NAME";
echo ;
echo "By default this starts an app in the current directory because the startproject command changes into the new project.";
echo ;
echo "By passing the [-p] option you can create an app in any project or destination. Give full /path/to/project if using this option"
elif [ $1 = "-p" ]; then
django-admin startapp $2 $3;
else
django-admin startapp $1;
fi
}
syncdb()
{
if [ $1 = "--help" ]; then
echo "Usage: syncdb PROJECT_NAME [ DB_NAME ]";
echo
echo "Include DB_NAME if you need to sync a database other than 'default'.";
elif [ $2 ]; then
cd {$DJANGOPATH}/$1; python manage.py syncdb --database=$2; cd ~;
else
cd {$DJANGOPATH}/$1; python manage.py syncdb;
fi
}
sqlflush()
{
if [ $1 = "--help" ]; then
echo "Usage: sqlflush PROJECT_NAME [ DB_NAME ]";
echo
echo "Include DB_NAME if you need to see sql commands for a database other than 'default'.";
elif [ $2 ]; then
cd {$DJANGOPATH}/$1; python manage.py sqlflush --database=$2; cd ~;
else
cd {$DJANGOPATH}/$1; python manage.py sqlflush; cd ~;
fi
}
shell()
{
if [ $1 = "--help" ]; then
echo "Usage: shell PROJECT_NAME";
else
cd {$DJANGOPATH}/$1; python manage.py shell;
fi
}
flushdb()
{
if [ $1 = "--help" ]; then
echo "Usage: flushdb PROJECT_NAME DB_NAME";
echo "This will delete all data from database DB_NAME, keeping the structure."
else
cd {$DJANGOPATH}/$1; python manage.py flush --database=$2
fi
}