from django.core.management.base import BaseCommand
from django.utils import timezone
from rog.models import TempUser  # アプリ名 'rog' を適切に変更してください

class Command(BaseCommand):
    help = 'Deletes expired temporary user records'

    def handle(self, *args, **options):
        expired_users = TempUser.objects.filter(expires_at__lt=timezone.now())
        count = expired_users.count()
        expired_users.delete()
        self.stdout.write(self.style.SUCCESS(f'Successfully deleted {count} expired temporary user records'))


# cron job の設定
# 0 3 * * * /path/to/your/python /path/to/your/manage.py cleanup_temp_users
