model_to_dict
Return a dict containing the data in instance suitable for passing as a Form's initial keyword argument.
def model_to_dict(
instance: Model,
fields: list = null,
exclude: list = null
) - > dict
Return a dict containing the data in instance suitable for passing as a Form's initial keyword argument.
Parameters
| Name | Type | Description |
|---|---|---|
| instance | Model | The Django model instance from which to extract data. |
| fields | list = null | An optional list of field names. If provided, return only the named. |
| exclude | list = null | An optional list of field names. If provided, exclude the named from the returned dict, even if they are listed in the fields argument. |
Returns
| Type | Description |
|---|---|
dict | A dictionary mapping field names to their corresponding values extracted from the model instance. |