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'))