I have the following type of template in Django:
<form .... >
<label class="control-label" for="id_quantity">Quantiy</label>
{{ form.quantity }}
<label class="control-label" for="id_title">Quantiy</label>
{{ form.title}}
</form>
The view contains a ModelForm object in its context from which the "form" variable in the template is derived.
Often, you can pass a form that is bound to data like request.POST. How do I load a form that is bound to the data of a specific instance of a model? Is there any special syntax?
There are two options here:
MyModelForm(instance=myInstanceModel)
MyModelForm(initial={ "my": "initial-data" })
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With