Skip to content

Instantly share code, notes, and snippets.

@dpineiden
Last active January 11, 2019 02:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dpineiden/937d36bdfd9148e6c6a344b58c538a71 to your computer and use it in GitHub Desktop.
Save dpineiden/937d36bdfd9148e6c6a344b58c538a71 to your computer and use it in GitHub Desktop.
Create App for Django with some extras
# OPTIONS >
#
# -n :: app name, obligatory
# -t :: create templates folder {0,1}
# -s :: create static folder {0,1}
# -m :: create media folder {0,1}
# -u :: create urls.py file {0,1}
# -i :: define project name o main folder
#
# how to run?
#
# ./startapp.sh -n NAME -t 1 -s 0 -i mi_web
#
project_name=$(pwd|awk -F'/' '{print $NF}')
install_file="./${project_name}/settings/installed.py"
echo "Creando apps en ${project_name}"
templates=1
static=1
media=0
urls=1
while getopts ntsmu: option
do
case "${option}"
in
n) app=${OPTARG};;
t) templates=${OPTARG};;
s) static=${OPTARG};;
m) media=${OPTARG};;
u) urls=${OPTARG};;
esac
done
echo "Creating "$app" folder"
mkdir ./apps/$app
echo "Creating app inside the folder ./apps/"$app
python manage.py startapp $app ./apps/$app
if [ $templates -eq 1 ]
then
echo "Creating templates"
mkdir ./apps/$app/templates
mkdir ./apps/$app/templates/$app
fi
if [ $static -eq 1 ]
then
echo "Creating static folder"
mkdir ./apps/$app/static
mkdir ./apps/$app/static/$app
fi
if [ $media -eq 1 ];
then
echo "Creating media folder"
mkdir ./apps/$app/media
fi
if [ $urls -eq 1 ];
then
echo "Creating urls file"
touch ./apps/$app/urls.py
fi
echo "Agregando app a INSTALLED_APPS -> apps.${app}"
sed -i "/]/i\ \"apps."$app"\"," $install_file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment