From: Guillaume Pellerin Date: Sun, 14 Feb 2021 22:49:23 +0000 (+0100) Subject: add command deleting postman messages older than 1 year X-Git-Tag: 1.4.3~30^2~1 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=80869618e51aa3893eea5ad81a065783462cc808;p=teleforma.git add command deleting postman messages older than 1 year --- diff --git a/teleforma/management/commands/teleforma-delete-old-messages.py b/teleforma/management/commands/teleforma-delete-old-messages.py new file mode 100644 index 00000000..e5edb2c3 --- /dev/null +++ b/teleforma/management/commands/teleforma-delete-old-messages.py @@ -0,0 +1,27 @@ +from optparse import make_option +from django.conf import settings +from django.core.management.base import BaseCommand, CommandError +from django.contrib.auth.models import User +from django.template.defaultfilters import slugify +from telemeta.models import * +from telemeta.util.unaccent import unaccent +from teleforma.models import * +from postman.models import Message +import logging +import datetime + + +class Command(BaseCommand): + help = "Delete postman messages olders than one year" + admin_email = 'webmaster@parisson.com' + + def handle(self, *args, **options): + date = datetime.datetime.now() + date.year = date.year - 1 + print(date) + messages = Message.objects.filter(sent_at__lte=datetime_now) + print(messages.count()) + for message in messages: + print(message.sent_at) + message.delete() +