Re: 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

21 views
Skip to first unread message
Message has been deleted

Lalit Suthar

unread,
Jun 1, 2021, 6:38:02 AM6/1/21
to django...@googlegroups.com
because you're passing commit=False with form2

On Tue, 1 Jun 2021 at 14:10, Hugh Frost <mohansar...@gmail.com> wrote:
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...@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.
Reply all
Reply to author
Forward
0 new messages