Skip to content

Instantly share code, notes, and snippets.

@zhasm
Last active December 20, 2015 10:59
Show Gist options
  • Save zhasm/6119376 to your computer and use it in GitHub Desktop.
Save zhasm/6119376 to your computer and use it in GitHub Desktop.
snippet bash function to make new command in django apps.
function djcmd () {
if [[ "$#" -lt 1 ]]
then
echo "Usage: $FUNCNAME <must_args> [optional_args]"
return
else
mkdir -p management/commands
touch management/__init__.py
touch management/commands/__init__.py
touch management/commands/_private.py
cat >> management/commands/$1.py <<EOF
from django.core.management.base import BaseCommand, CommandError
from optparse import make_option
class Command(BaseCommand):
option_list = BaseCommand.option_list + (
make_option('--delete',
action='store_true',
dest='delete',
default=False,
help='Some help '),
)
def handle(self, *args, **options):
for poll_id in args:
try:
print poll_id
except Exception as e:
raise CommandError('Error' + str(e))
self.stdout.write('Done!')
EOF
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment