0
當我正在生成表格時,是否有任何方法使用來自模型實例的數據預填充表單字段?從Django模板請求ModelForm實例
假設我有一個廣告系列模型,並且我循環列出表中的實例值和表單字段。
E.g.像這樣:
{% for campaign in all_campaigns %}
<tr>
<td>{{ forloop.counter }}</a></td>
<td>{{ campaign.name }}</td>
<td>{{ campaign.get_status_display }}</td>
<td>{{ campaign.start_date }}</td>
<td>{{ campaign.end_date }}</td>
</tr>
# --> have these form fields based on the campaign
# instance that's being rendered above, so clicking an
# edit button will edit this campaign instance ?
<tr class='initially-hidden'>
<td>{{ campaign.id }}</a></td>
<td>{{ form.name}} </td>
<td>{{ form.status }}</td>
<td>{{ form.start_date }}</td>
<td>{{ form.end_date }}</td>
</tr>
{% endfor %}
在此先感謝!