]> git.parisson.com Git - teleforma.git/commitdiff
add command deleting postman messages older than 1 year
authorGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Sun, 14 Feb 2021 22:49:23 +0000 (23:49 +0100)
committerGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Sun, 14 Feb 2021 22:49:23 +0000 (23:49 +0100)
teleforma/management/commands/teleforma-delete-old-messages.py [new file with mode: 0644]

diff --git a/teleforma/management/commands/teleforma-delete-old-messages.py b/teleforma/management/commands/teleforma-delete-old-messages.py
new file mode 100644 (file)
index 0000000..e5edb2c
--- /dev/null
@@ -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()
+