Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Django shortcut functions

By: a guest on Jun 1st, 2012  |  syntax: Bash  |  size: 2.33 KB  |  views: 566  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. ### Handy functions if you have a single folder that contains a directory for each project
  2. # shortcut commands for Django
  3. ### --- Don't use a trailing slash when defining you path
  4.  
  5.  DJANGOPATH="/path/to/projects/container"
  6.  
  7. runserver()
  8. {
  9.         if [ $1 = "--help" ]; then
  10.                 echo "Usage: runserver PROJECT_NAME";
  11.         else
  12.                 cd ${DJANGOPATH}/$1; python manage.py runserver; cd ~;
  13.         fi
  14. }
  15.  
  16. sql()
  17. {
  18.   if [ $1 = "--help" ]; then
  19.     echo "Usage: sql PROJECT_NAME APP_NAME";
  20.   else
  21.     cd ${DJANGOPATH}/$1; python manage.py sql $2; cd ~;
  22.   fi
  23. }
  24.  
  25. startproject()
  26. {
  27.   if [ $1 = "--help" ]; then
  28.     echo "Usage: startproject PROJECT_NAME";
  29.   else
  30.     cd {$DJANGOPATH}; django-admin startproject $1 project; cd $1;
  31.   fi
  32. }
  33.  
  34. startapp()
  35. {
  36.   if [ $1 = "--help" ]; then
  37.     echo "Usage: startapp [ -p ] APP_NAME PROJECT_NAME";
  38.     echo ;
  39.     echo "By default this starts an app in the current directory because the startproject command changes into the new project.";
  40.     echo ;
  41.     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"
  42.   elif [ $1 = "-p" ]; then
  43.     django-admin startapp $2 $3;
  44.   else
  45.     django-admin startapp $1;
  46.   fi
  47. }
  48.  
  49. syncdb()
  50. {
  51.   if [ $1 = "--help" ]; then
  52.     echo "Usage: syncdb PROJECT_NAME [ DB_NAME ]";
  53.     echo
  54.     echo "Include DB_NAME if you need to sync a database other than 'default'.";
  55.   elif [ $2 ]; then
  56.     cd {$DJANGOPATH}/$1; python manage.py syncdb --database=$2; cd ~;
  57.   else
  58.     cd {$DJANGOPATH}/$1; python manage.py syncdb;
  59.   fi
  60. }
  61.  
  62. sqlflush()
  63. {
  64.   if [ $1 = "--help" ]; then
  65.     echo "Usage: sqlflush PROJECT_NAME [ DB_NAME ]";
  66.     echo
  67.     echo "Include DB_NAME if you need to see sql commands for a database other than 'default'.";
  68.   elif [ $2 ]; then
  69.     cd {$DJANGOPATH}/$1; python manage.py sqlflush --database=$2; cd ~;
  70.   else
  71.     cd {$DJANGOPATH}/$1; python manage.py sqlflush; cd ~;
  72.   fi
  73. }
  74.  
  75. shell()
  76. {
  77.   if [ $1 = "--help" ]; then
  78.     echo "Usage: shell PROJECT_NAME";
  79.   else
  80.      cd {$DJANGOPATH}/$1; python manage.py shell;
  81.   fi
  82. }
  83.  
  84. flushdb()
  85. {
  86.   if [ $1 = "--help" ]; then
  87.     echo "Usage: flushdb PROJECT_NAME DB_NAME";
  88.     echo "This will delete all data from database DB_NAME, keeping the structure."
  89.   else
  90.     cd {$DJANGOPATH}/$1; python manage.py flush --database=$2
  91.   fi
  92. }
clone this paste RAW Paste Data