]> git.parisson.com Git - teleforma.git/commitdiff
add django command to delete messages older than 1 year
authorGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Mon, 15 Feb 2021 10:09:40 +0000 (11:09 +0100)
committerGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Mon, 15 Feb 2021 10:09:40 +0000 (11:09 +0100)
teleforma/management/commands/teleforma-delete-jqchat-messages.py [new file with mode: 0644]

diff --git a/teleforma/management/commands/teleforma-delete-jqchat-messages.py b/teleforma/management/commands/teleforma-delete-jqchat-messages.py
new file mode 100644 (file)
index 0000000..c281d53
--- /dev/null
@@ -0,0 +1,20 @@
+
+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 jqchat.models import Message
+import datetime
+
+
+class Command(BaseCommand):
+    help = "Delete jqchat messages older than 1 year"
+
+    def handle(self, *args, **options):
+        date_now = datetime.datetime.now()
+        date_old = date_now.replace(year=date_now.year-1)
+        print(date_old)
+        messages = Message.objects.filter(created__lte=date)
+        print(messages.count())
+        for message in messages:
+            message.delete()