Skip to main content

construct_instance

Construct and return a model instance from the bound form's cleaned_data, but do not save the returned instance to the database.

def construct_instance(
form: Form,
instance: Model,
fields: list = null,
exclude: list = null
) - > Model

Construct and return a model instance from the bound form's cleaned_data, but do not save the returned instance to the database.

Parameters

NameTypeDescription
formFormThe bound Django form instance containing the cleaned data to be applied to the model.
instanceModelThe existing Django model instance to be updated with the form data.
fieldslist = nullAn optional list of field names; if provided, only these fields will be updated on the instance.
excludelist = nullAn optional list of field names to be skipped during the instance update process.

Returns

TypeDescription
ModelThe updated Django model instance populated with data from the form, but not yet persisted to the database.