[Answer]-Multiple ModelForm in Django

1πŸ‘

βœ…

I think you should use the prefix even in GET mode:

def create(request):
>>   a_form = AForm(prefix="a") 
>>   b_form = BForm(prefix="b")
     if request.method == 'POST':
          a_form = AForm(request.POST, prefix="a")
          b_form  = BForm(request.POST, prefix="b")
     if a_form.is_valid() and b_form.is_valid():
          a = a_form.save()
>>        b = b_form.save(commit=False)
>>        b.a = a
>>        b.save()
          return HttpResponseRedirect('/companies/detail/{b.id}')
     return render_to_response('companies/signup.html',{'AForm':a_form , 'BForm': b_form }, context_instance=RequestContext(request))

Leave a comment