这是我的代码:
PartFormSet = inlineformset_factory(ReservationPaper, ReservationPaperPart,
ReservationPaperPartEditForm, extra=0)
if request.method == "POST":
try:
part_formset = PartFormSet(data=request.POST, instance=rp)
except:
return HttpResponseRedirect(request.path_info)
rp_form = ReservationPaperForm(instance=rp, data=request.POST)
if part_formset.is_valid() and rp_form.is_valid():
rp_form.save()
for part_form in part_formset.forms:
part_form.save()
return HttpResponseRedirect(reverse("internal:documents:display_reservation_paper",
args=[rp.id]))
else:
rp_form = ReservationPaperForm(instance=rp)
part_formset = PartFormSet(instance=rp)
它为每个part_formset实例呈现删除复选框,但是,当我提交表单时,只会编辑条目,而不会删除。
答案 0 :(得分:2)
保存表单集时,您没有做任何特别的事情,因此您只需调用part_formset.save()
而不是单独遍历表单。