haikal/inventory/management/commands/deactivate_expired_plans.py
2025-05-01 17:04:05 +03:00

18 lines
561 B
Python

from django.core.management.base import BaseCommand
from django.utils import timezone
from plans.models import UserPlan
class Command(BaseCommand):
help = 'Deactivates expired user plans'
def handle(self, *args, **options):
expired_plans = UserPlan.objects.filter(
active=True,
expire__lt=timezone.now()
)
count = expired_plans.count()
for plan in expired_plans:
plan.expire_account()
self.stdout.write(self.style.SUCCESS(f'Successfully deactivated {count} expired plans'))