我正在尝试添加不带 javascript 的内联行,类似于此 SO 帖子:Django:添加不带 javascript 的内联表单集行
但是,当我按添加时,表单会重新初始化并且不会添加额外的行。我究竟做错了什么?
表格.py
IndicatorFormSet2 = inlineformset_factory(Disease, Indicator)
视图.py
disease = get_object_or_404(Disease, pk=disease_id)
if request.method == "POST":
if 'add' in request.POST:
cp = request.POST.copy()
cp['form-TOTAL_FORMS'] = int(cp['form-TOTAL_FORMS'])+1
indicatorInlineFormSet = IndicatorFormSet2(request.POST, cp, prefix='form')
return HttpResponseRedirect(reverse('drui', kwargs={'disease_id':disease_id}))
if indicatorInlineFormSet.is_valid():
indicatorInlineFormSet.save()
return HttpResponseRedirect(reverse('valdrui', kwargs={'disease_id':disease_id}))
else:
indicatorInlineFormSet = IndicatorFormSet2(instance=disease, prefix='form')