我正在尝试在 django 中编辑具有内联表单集的更新视图。下面是 model.py、forms.py、views.py 和模板文件。表单没有保存,所以我在views.py的post方法中放置了一个print(actor_form)来看看发生了什么。我得到以下 html 代码:
<input type="hidden" name="actor-TOTAL_FORMS" value="1" id="id_actor-TOTAL_FORMS" /><input type="hidden" name="actor-INITIAL_FORMS" value="1" id="id_actor-INITIAL_FORMS" /><input type="hidden" name="actor-MIN_NUM_FORMS" value="0" id="id_actor-MIN_NUM_FORMS" /><input type="hidden" name="actor-MAX_NUM_FORMS" value="1000" id="id_actor-MAX_NUM_FORMS" />
<tr><td colspan="2"><ul class="errorlist nonfield"><li>(Hidden field id) This field is required.</li></ul></td></tr>
<tr><th><label for="id_actor-0-actorName">ActorName:</label></th><td><input type="text" name="actor-0-actorName" value="www" maxlength="50" id="id_actor-0-actorName" /></td></tr>
<tr><th><label for="id_actor-0-DELETE">Delete:</label></th><td><label for="id_actor-0-DELETE" class="checkbox-inline"><input type="checkbox" name="actor-0-DELETE" id="id_actor-0-DELETE" />
</label><input type="hidden" name="actor-0-id" id="id_actor-0-id" /><input type="hidden" name="actor-0-useCase" id="id_actor-0-useCase" /></td></tr>
Run Code Online (Sandbox Code Playgroud)
在上面的第二行中,您可以看到 - (隐藏字段 id) 该字段是必填字段。
我相信这是导致内联无法保存的原因,但我不知道如何修复它。
这是 models.py
class Profile(models.Model):
profileName = models.CharField(max_length=50)
profileBoundary = models.CharField(max_length=3, choices …Run Code Online (Sandbox Code Playgroud)