Last active
December 20, 2015 10:59
-
-
Save zhasm/6119376 to your computer and use it in GitHub Desktop.
snippet bash function to make new command in django apps.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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