haikal/inventory/management/commands/deactivate_expired_plans.py
2025-06-22 13:25:54 +03:00

19 lines
551 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")
)