@@ -0,0 +1,1821 @@
+from django.contrib.auth import get_user_model%0Afrom django.core.management.base import BaseCommand, CommandError%0A%0AUserModel = get_user_model()%0A%0A%0Aclass Command(BaseCommand):%0A    %22%22%22%0A    A management command for suspending one or more users.%0A    %22%22%22%0A%0A    help = 'Suspend users by username'%0A%0A    def add_arguments(self, parser):%0A        parser.add_argument('-u', '--username',%0A                            dest='username',%0A                            required=False,%0A                            help=('one or more usernames, comma separated'))%0A        parser.add_argument('-i', '--id',%0A                            dest='id',%0A                            required=False,%0A                            help=('one or more ids, comma separated'))%0A%0A    def handle(self, *args, **options):%0A        users_to_suspend = %5B%5D%0A%0A        if options%5B'username'%5D:%0A            usernames = options%5B'username'%5D.split(',')%0A            for username in usernames:%0A                try:%0A                    users_to_suspend.append(%0A                        UserModel.objects.get(username=username))%0A                except UserModel.DoesNotExist:%0A                    raise CommandError('Username %22%7B%7D%22 does not exist!'%0A                                       .format(username))%0A%0A        if options%5B'id'%5D:%0A            ids = options%5B'id'%5D.split(',')%0A            for id_str in ids:%0A                try:%0A                    users_to_suspend.append(%0A                        UserModel.objects.get(id=int(id_str)))%0A                except UserModel.DoesNotExist:%0A                    raise CommandError('User ID %22%7B%7D%22 does not exist!'%0A                                       .format(id_str))%0A%0A        for user in users_to_suspend:%0A            user.is_active = False%0A            user.save()%0A            print('%7B%7D (ID: %7B%7D) is suspended.'.format(user.username, user.id))%0A

Add management command to suspend users