This commit is contained in:
Ross
2022-01-06 08:27:00 +00:00
parent 35b163a887
commit 3d4f5a4a21
2 changed files with 4 additions and 17 deletions
+4 -15
View File
@@ -111,22 +111,11 @@ class AnatomyQuestionForm(ModelForm):
def save(self, commit=True):
# Get the unsaved Pizza instance
instance = ModelForm.save(self, False)
# Prepare a 'save_m2m' method for the form,
old_save_m2m = self.save_m2m
def save_m2m():
old_save_m2m()
# This is where we actually link the pizza with toppings
instance.exams.clear()
for exam in self.cleaned_data["exams"]:
instance.exams.add(exam)
self.save_m2m = save_m2m
# Do we need to save all changes now?
# if commit:
instance.save()
for exam in self.cleaned_data["exams"]:
exam.exam_questions.add(instance)
self.save_m2m()
return instance