发布我发现的解决方案。看一下Generic_inlineformset_factory的来源。
我认为:-
def edit_contact(request): c={} profile = request.user.get_profile() EmployeeFormSet = generic_inlineformset_factory(PhoneNumber,extra=0,can_delete=False) EmployeeFormSet1=generic_inlineformset_factory(EmailAddress,extra=0,can_delete=False) EmployeeFormSet2 = generic_inlineformset_factory(Address, extra = 0, can_delete=False) if request.method == "POST": p_formset = EmployeeFormSet(data=request.POST, instance = profile), e_formset = EmployeeFormSet1(data=request.POST, instance = profile), a_formset = EmployeeFormSet2(data=request.POST, instance = profile), for e in p_formset:if e.is_valid(): e.save() for e in e_formset:if e.is_valid(): e.save() for e in a_formset:if e.is_valid(): e.save() return HttpResponseRedirect('/forms/sucess-edit/') else: p_formset = EmployeeFormSet(instance = profile), e_formset = EmployeeFormSet1(instance = profile), a_formset = EmployeeFormSet2(instance = profile), c.update({'p_formset': p_formset, 'e_formset': e_formset,'a_formset': a_formset}) return render_to_response('forms/edit_contact.html',c, context_instance=RequestContext(request))
这项工作成功完成,我认为如果有人在他们的模型中使用“通用关系”,并且想要创建一个用于编辑该信息的表格,将是一个很好的帮助。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)