擅长:python、mysql、java
<p>使用内联表单集时,需要提供与对象相关的实例。</p>
<pre><code># First, fetch the instance from the db
workout = code_that_fetches_instance()
if request.method == "POST" :
formset = WorkoutInlineFormSet(request.POST, instance=workout)
...
else:
formset = WorkoutInlineFormSet(instance=workout)
</code></pre>
<p>有关详细信息,请参阅<a href="https://docs.djangoproject.com/en/1.9/topics/forms/modelforms/#using-an-inline-formset-in-a-view" rel="nofollow">using an inline formset in a view</a>上文档中的示例。</p>
<p>如果<code>workout</code>和<code>exercise</code>是您的模型,您应该遵循python约定,将它们重命名为<code>Workout</code>和<code>Exercise</code>。小写<code>workout</code>应该是表单集中所有练习链接到的实例。</p>