diff --git a/longs/forms.py b/longs/forms.py index 97a953bc..13ce2661 100755 --- a/longs/forms.py +++ b/longs/forms.py @@ -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"]