Tuesday, June 1, 2021

Hi all, i'm using 2 modelforms in one view function one as foreign key but when i submit babyform2 not storing in database. anyone please fix this

def detail(request):
    if request.method == 'POST':
        baby_form1 = BabyForm1(data=request.POST)
        baby_form2 = BabyForm2(data=request.POST)

        if baby_form1.is_valid() and baby_form2.is_valid():
            baby_form1.save()
            print(baby_form1)
            baby_form2.baby_form1 = baby_form1
            baby_form2.save(commit=False)
            print(baby_form2)
            baby_form2.baby_form1
           
            return redirect('userapp:home')

           
    else:
        baby_form1 = BabyForm1()
        baby_form2 = BabyForm2()
    return render(request,'userapp_temp/profile.html', {'baby_form1':baby_form1, 'baby_form2':baby_form2,})

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/73c21cb8-9127-401c-88b2-fa94446cc37bn%40googlegroups.com.

No comments:

Post a Comment