Code

Opened 6 years ago

Closed 6 years ago

#6178 closed (invalid)

ModelForm too many restrictions.

Reported by: bear330 Owned by: nobody
Component: Forms Version: master
Severity: Keywords: ModelForm, form.save
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

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.

Attachments (0)

Change History (2)

comment:1 Changed 6 years ago by Karen Tracey <kmtracey@…>

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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.

comment:2 Changed 6 years ago by ubernostrum

  • Resolution set to invalid
  • Status changed from new to 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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.