From 714eeb188c67a6b61dfd132f0869e7679d91c8bf Mon Sep 17 00:00:00 2001 From: maheshgudi Date: Thu, 12 Jul 2018 20:08:20 +0530 Subject: Fix multiple testcase error --- yaksh/models.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'yaksh/models.py') diff --git a/yaksh/models.py b/yaksh/models.py index 5d17dba..12bada8 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -1360,9 +1360,12 @@ class QuestionPaper(models.Model): random.shuffle(testcases) testcases_ids = ",".join([str(tc.id) for tc in testcases] ) - TestCaseOrder.objects.create( - answer_paper=ans_paper, question=question, - order=testcases_ids) + if not TestCaseOrder.objects.filter( + answer_paper=ans_paper, question=question + ).exists(): + TestCaseOrder.objects.create( + answer_paper=ans_paper, question=question, + order=testcases_ids) ans_paper.questions_order = ",".join(question_ids) ans_paper.save() @@ -2200,4 +2203,7 @@ class TestCaseOrder(models.Model): order = models.TextField() + class Meta: + unique_together = ("answer_paper", "question", "order") + ############################################################################## -- cgit