Opened 17 years ago
Closed 17 years ago
#6178 closed (invalid)
ModelForm too many restrictions.
Reported by: | bear330 | Owned by: | nobody |
---|---|---|---|
Component: | Forms | Version: | dev |
Severity: | Keywords: | ModelForm, form.save | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Originally, I used form_for_model for form generation from model and worked fine.
After form_for_model deprecated, I try to use ModelForm instead, but some problems I occurred.
First, I never use form.save() method to save my model instance. My preferred way is to get data from form, do some required processes, and set it to my model instance then save it.
ModelForm implementation forces me to pass a model instance in form's constructor. This is not backward compatible. All of my view must pass a useless model instance to it.
I don't mind to change my code to follow django's new development version, but this parameter is not necessary for people who don't need to use form.save() feature.
I just want to generate a form from declared model. That's all I need..
ModelForm implementation tied 'generate a form from model' feature and 'save a form which generated from model' feature together. This truly bothered me.
For the same reason, the ModelForm implementation restricts multiple inheritance from two or more form generated from model. All of that are for form.save() method.
I think the form.save is a great feature in newforms library, but it shouldn't restrict the people who don't need it. All validations can be done in form.save method and can raise exceptions if form is not fulfill the requirement but in form generation.
Thanks.
Change History (2)
comment:1 by , 17 years ago
comment:2 by , 17 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
You can already get the data out of a ModelForm
without saving a model object; the commit=False
argument to save()
works exactly the same way.
Another ticket is already dealing with the constructor's argument signature and required instance.
Given that, I don't see an actual issue here.
Note #6162 is getting rid of the required instance parameter for ModelForm. Not sure if it also addresses your concern about multiple inheritance, maybe you could take a look and see? There's also a pointer in that ticket to the thread on the dev list that has relevant discussion.