diff options
author | Ernesto Rico-Schmidt <e.rico.schmidt@gmail.com> | 2011-06-04 18:00:43 (GMT) |
---|---|---|
committer | Ernesto Rico-Schmidt <e.rico.schmidt@gmail.com> | 2011-06-04 18:00:43 (GMT) |
commit | d73d756e3671688f78e15c69e572f73a825db232 (patch) | |
tree | 9840a9d0b66e35cf039886556d5558eb70b7afe2 | |
parent | cecabcee03cc8e0d83fe78e2a31661181fd89c8c (diff) |
added deleteuser command.
-rw-r--r-- | program/management/commands/deleteuser.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/program/management/commands/deleteuser.py b/program/management/commands/deleteuser.py new file mode 100644 index 0000000..27ce61e --- /dev/null +++ b/program/management/commands/deleteuser.py @@ -0,0 +1,22 @@ +from django.contrib.auth.models import User +from django.core.management.base import BaseCommand, CommandError + +from optparse import make_option + +class Command(BaseCommand): + help = 'deletes an user' + option_list = BaseCommand.option_list + ( + make_option('--username', dest='username', default=None, help='Specifies the username.'), + ) + + def handle(self, *args, **options): + username = options.get('username', None) + + if not username: + raise CommandError("You must use --username.") + try: + User.objects.get(username=username).delete() + except User.DoesNotExist: + raise 'user does not exist.' + else: + print 'user deleted succesfuly.'
\ No newline at end of file |