You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

14 lines
454 B

  1. from datetime import timedelta
  2. from django.core.management.base import BaseCommand
  3. from django.utils import timezone
  4. from djmail.models import Message
  5. class Command(BaseCommand):
  6. help = 'Prune stored email messages older than 7 days'
  7. def handle(self, *args, **options):
  8. cutoff = timezone.now() - timedelta(days=7)
  9. n, _ = Message.objects.filter(sent_at__lt=cutoff).delete()
  10. return "Done! Pruned %d email messages." % n