lib.itmens/users/management/commands/disable_user.py

21 lines
486 B
Python
Raw Normal View History

2022-01-06 04:22:12 +00:00
from datetime import timedelta
from django.core.management.base import BaseCommand
2022-01-06 04:22:12 +00:00
from django.utils import timezone
from users.models import User
2022-01-06 04:22:12 +00:00
class Command(BaseCommand):
2023-01-11 19:11:31 -05:00
help = "disable user"
2022-01-06 04:22:12 +00:00
def add_arguments(self, parser):
2023-01-11 19:11:31 -05:00
parser.add_argument("id", type=int, help="user id")
2022-01-06 04:22:12 +00:00
def handle(self, *args, **options):
2023-01-11 19:11:31 -05:00
h = int(options["id"])
u = User.objects.get(pk=h)
2022-01-06 04:22:12 +00:00
u.is_active = False
u.save()
print(f"{u} disabled")