Wednesday, January 18, 2017

Re: prepopulate form with model instance values using UpdateView and ModelForm

On Wednesday 18 January 2017 04:44:01 dauer.benjamin wrote:

 

> Question for you all. Appreciate any insight you can give. So I have a

> class-based view (UpdateView) and a ModelForm. I want the form to

> pre-populate with data from a model instance.

 

It feels like you're doing work that's already done properly when you setup your URLs right.

The operations work like this:

  • Create view: doesn't get an instance ID (but creates one) and fills form with values set by defaults keyword argument on model fields.
  • Update view: gets an instance ID and fills it with field values from the instance. Any missing values get assigned defaults.
  • Delete view: gets an instance ID and removes it. Field values typically do not come into play.

Does this conflict with what you're trying to accomplish?

--

Melvyn Sopacua

No comments:

Post a Comment