This commit is contained in:
Ross
2021-11-25 18:55:13 +00:00
parent 8ea4bec5e5
commit 4403f97548
+23
View File
@@ -118,6 +118,29 @@ class LongSeriesForm(ModelForm):
widget=FilteredSelectMultiple(verbose_name="Long", is_stacked=False),
)
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.long.clear()
for long in self.cleaned_data["long"]:
instance.long.add(long)
self.save_m2m = save_m2m
# Do we need to save all changes now?
# if commit:
instance.save()
self.save_m2m()
return instance
class Meta:
model = LongSeries
exclude = ["author"]