From 863438308672cff04e36800721eefbb454892d64 Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Tue, 22 Jun 2021 13:59:58 +0200 Subject: [PATCH] full annotation delete --- .../commands/teleforma-delete-annotations.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/teleforma/management/commands/teleforma-delete-annotations.py b/teleforma/management/commands/teleforma-delete-annotations.py index 81088ce6..47eede5f 100644 --- a/teleforma/management/commands/teleforma-delete-annotations.py +++ b/teleforma/management/commands/teleforma-delete-annotations.py @@ -13,7 +13,7 @@ class Command(BaseCommand): help = "Delete script annotations from previous year" def handle(self, *args, **options): - date = datetime.datetime.now() + date_now = datetime.datetime.now() date_old = date_now.replace(year=date_now.year-1, month=12, day=31) print(date_old) scripts = Script.objects.filter(date_submitted__lte=date_old) @@ -28,4 +28,13 @@ class Command(BaseCommand): annotation_comment.delete() script.delete() + scripts = Script.objects.all() + for annotation_comment in AnnotationComment.objects.all(): + if not scripts.objects.filter(uuid=annotation_comment.uuid): + annotation_comment.delete() + for annotation in Annotation.objects.all(): + if not scripts.objects.filter(uuid=annotation.uuid): + annotation.delete() + + \ No newline at end of file -- 2.39.5