[Answer]-Behaviour of Django's forms.ModelForm.save(): Why does models.save_instance not work via parent?

1👍

Don’t update the cleaned_data. Call save() with commit=False, set the employee then save it to the db.

class EmployeeForm(forms.ModelForm):
    second_form = None

    def save(self):
        employee = super(ShiftSubForm, self).save()
        shift = self.second_form.save(commit=False)
        shift.employee = employee
        shift.save()
        return employee

    class Meta:
        model = Employee

Leave a comment