From 31ed4976dcec3b479afdd67a5ed55ab122b0a10e Mon Sep 17 00:00:00 2001 From: Ross Date: Sun, 17 Oct 2021 08:49:04 +0100 Subject: [PATCH] . --- generic/views.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/generic/views.py b/generic/views.py index 8d9cd5df..0532f601 100644 --- a/generic/views.py +++ b/generic/views.py @@ -121,7 +121,9 @@ def generic_exam_json_edit(request): question_objects = Question.objects.filter(pk__in=question_ids) for i in question_ids: - exam.exam_questions.add(i) + # We get an integrity error if we try to add an object that already exists + if not question_objects.filter(pk=i).exists(): + exam.exam_questions.add(i) #exam.exam_questions.add(question_objects) exam.save() data = {"status": "success"}