From 3d4f5a4a21c36715643b7ffbf4a0a3cf4ced9a1d Mon Sep 17 00:00:00 2001 From: Ross Date: Thu, 6 Jan 2022 08:27:00 +0000 Subject: [PATCH] . --- anatomy/forms.py | 19 ++++--------------- rapids/forms.py | 2 -- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/anatomy/forms.py b/anatomy/forms.py index 241801b2..bfd8b7f9 100644 --- a/anatomy/forms.py +++ b/anatomy/forms.py @@ -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 diff --git a/rapids/forms.py b/rapids/forms.py index 6cfb0f34..4b30fe6d 100755 --- a/rapids/forms.py +++ b/rapids/forms.py @@ -128,12 +128,10 @@ class RapidForm(ModelForm): ) def save(self, commit=True): - # Get the unsaved Pizza instance instance = ModelForm.save(self, False) instance.save() for exam in self.cleaned_data["exams"]: - # exam = Exam.objects.get(pk=exam_pk) exam.exam_questions.add(instance) # # Prepare a 'save_m2m' method for the form,