deleteoldnotifications.py 567 B

123456789101112131415161718
  1. from datetime import timedelta
  2. from django.conf import settings
  3. from django.core.management.base import BaseCommand
  4. from django.utils import timezone
  5. from misago.notifications.models import Notification
  6. class Command(BaseCommand):
  7. help = 'Deletes old notifications.'
  8. def handle(self, *args, **options):
  9. cutoff = timedelta(days=settings.MISAGO_NOTIFICATIONS_MAX_AGE)
  10. cutoff_date = timezone.now() - cutoff
  11. Notification.objects.filter(date__lte=cutoff_date).delete()
  12. self.stdout.write('Old notifications have been deleted')