]> git.parisson.com Git - teleforma.git/commitdiff
add scripts cleanup script
authorGuillaume Pellerin <guillaume.pellerin@parisson.com>
Mon, 12 Jan 2026 09:59:44 +0000 (10:59 +0100)
committerGuillaume Pellerin <guillaume.pellerin@parisson.com>
Mon, 12 Jan 2026 09:59:44 +0000 (10:59 +0100)
teleforma/management/commands/teleforma-cleanup-scripts.py [new file with mode: 0644]

diff --git a/teleforma/management/commands/teleforma-cleanup-scripts.py b/teleforma/management/commands/teleforma-cleanup-scripts.py
new file mode 100644 (file)
index 0000000..3e4ddc9
--- /dev/null
@@ -0,0 +1,13 @@
+from django.core.management.base import BaseCommand
+from teleforma.exam.models import Script
+from datetime import datetime, timedelta
+
+
+class Command(BaseCommand):
+    help = "Delete all exam scripts older than a number of days"
+
+    def handle(self, *args, **options):
+        days = args[0]
+        date_limit = datetime.today() - timedelta(days=days)
+        for script in Script.objects.filter(date_added__lte=date_limit):
+            script.delete()