From 80869618e51aa3893eea5ad81a065783462cc808 Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Sun, 14 Feb 2021 23:49:23 +0100 Subject: [PATCH] add command deleting postman messages older than 1 year --- .../commands/teleforma-delete-old-messages.py | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 teleforma/management/commands/teleforma-delete-old-messages.py 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() + -- 2.39.5