ModelFormset ignores form properties
|Reported by:||Owned by:||jkocherhans|
|Cc:||justin1@…, james@…, alan.justino@…||Triage Stage:||Accepted|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
The implementation of modelformset_factory and inlineformset_factory ignore 'fields' and 'excludes' attributes of the supplied form (in fact all of Meta), and only use the values passed to the factory function.
Also the ModelFormset and InlineFormset 'save' method ignores the 'save' method of the supplied form.
class MyModelForm (django.forms.models.ModelForm): class Meta: model = models.MyModel fields = ('field1', 'field2') def save(self): m = super(MyModelForm, self).save() do_something_with(m) return m MyFormSet = modelformset_factory(models.MyModel, MyModelForm) fset = MyFormSet()
The forms that are part of fset have all fields of models.MyModel and not just 'field1' and 'field2' as expected.
Also fset.save() will not call 'do_something_with' on the models saved.
Much of the functionality of the ModelForm is ignored when used as part of a formset. This may be intended behavior, but it is not mentioned in the manual as far as I can see, and is not what one might expect.
Change History (20)
comment:1 Changed 8 years ago by
|Patch needs improvement:||unset|
|Triage Stage:||Unreviewed → Design decision needed|