From 4343c14fb9a2c13599573903ada0924502490b5b Mon Sep 17 00:00:00 2001 From: Ross Date: Wed, 5 Jan 2022 19:11:22 +0000 Subject: [PATCH] . --- rapids/forms.py | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/rapids/forms.py b/rapids/forms.py index d2f6b0dd..90e509ed 100755 --- a/rapids/forms.py +++ b/rapids/forms.py @@ -127,23 +127,29 @@ class RapidForm(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() - self.save_m2m() + + for exam_pk 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, +# 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() +# self.save_m2m() return instance