.
This commit is contained in:
+4
-15
@@ -111,22 +111,11 @@ class AnatomyQuestionForm(ModelForm):
|
|||||||
def save(self, commit=True):
|
def save(self, commit=True):
|
||||||
# Get the unsaved Pizza instance
|
# Get the unsaved Pizza instance
|
||||||
instance = ModelForm.save(self, False)
|
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()
|
instance.save()
|
||||||
|
|
||||||
|
for exam in self.cleaned_data["exams"]:
|
||||||
|
exam.exam_questions.add(instance)
|
||||||
|
|
||||||
self.save_m2m()
|
self.save_m2m()
|
||||||
|
|
||||||
return instance
|
return instance
|
||||||
|
|||||||
@@ -128,12 +128,10 @@ class RapidForm(ModelForm):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def save(self, commit=True):
|
def save(self, commit=True):
|
||||||
# Get the unsaved Pizza instance
|
|
||||||
instance = ModelForm.save(self, False)
|
instance = ModelForm.save(self, False)
|
||||||
instance.save()
|
instance.save()
|
||||||
|
|
||||||
for exam in self.cleaned_data["exams"]:
|
for exam in self.cleaned_data["exams"]:
|
||||||
# exam = Exam.objects.get(pk=exam_pk)
|
|
||||||
exam.exam_questions.add(instance)
|
exam.exam_questions.add(instance)
|
||||||
|
|
||||||
# # Prepare a 'save_m2m' method for the form,
|
# # Prepare a 'save_m2m' method for the form,
|
||||||
|
|||||||
Reference in New Issue
Block a user