From dd3f738ebeb46bf6c09385785d8b1bba2aaa8ed9 Mon Sep 17 00:00:00 2001 From: Ihsan Ullah Date: Wed, 7 Feb 2024 20:49:40 +0500 Subject: [PATCH] do not delete original submission when are reun is deleted, similarly do not delete rerun submission when original is deleted --- src/apps/competitions/models.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/apps/competitions/models.py b/src/apps/competitions/models.py index 4b87ec35a..f3bc3823d 100644 --- a/src/apps/competitions/models.py +++ b/src/apps/competitions/models.py @@ -500,10 +500,17 @@ def __str__(self): return f"{self.phase.competition.title} submission PK={self.pk} by {self.owner.username}" def delete(self, **kwargs): + + # Check if any other submissions are using the same data + other_submissions_using_data = Submission.objects.filter(data=self.data).exclude(pk=self.pk).exists() + + if not other_submissions_using_data: + # If no other submissions are using the same data, delete it + self.data.delete() + # Also clean up details on delete self.details.all().delete() - # Call this here so that the data_file for the submission also gets deleted from storage - self.data.delete() + super().delete(**kwargs) def save(self, ignore_submission_limit=False, **kwargs):