我有下面的视图代码
def edit_pal(request,pal_id):
pals=palabout.objects.get(id=pal_id)
form2=editpalForm(request.POST or None,instance=pals)
RecipeIngredientFormset = modelformset_factory(palabout, form=editspalForm,extra=0)
formset = RecipeIngredientFormset(request.POST or None,prefix=pals)
context={
"formset": formset,
"form2":form2,
"pals":pals
}
if request.method == 'POST':
if form2.is_valid() and formset.is_valid():
parent = form2.save(commit=False)
parent.save()
for form in formset:
child = form.save(commit=False)
child.recipe = parent
child.save()
context['message']='Data Saved'
return redirect('hod:manage_pal')
return render(request,"edit-pal.html",context)
我删除了formset.is_valid
,所以它的工作,但它不工作时,我添加了更多的使用formset.is_valid
,所以为什么不保存文件或详细信息显示?有人能帮助这个吗?
1条答案
按热度按时间fae0ux8s1#
我认为你只需要重定向,如果表单是有效的,所以试试这个视图: