[Django]-Foreign Key related form Saving in Django

3👍

You can try this

if request.method == 'POST':
    spf = StudentPotentialForm(request.POST)
    if spf.is_valid():
        osp = spf.save()
    else :
       #raise error

    student = Student.objects.get(id=student_id)
    scf = StudentCorrespondenceForm(request.POST)
    if scf.is_valid():
        osc = scf.save(commit=False)
        osc.student = student
        osc.student_p = osp
        osc.save()
    else:
        # raise error.
👤Rohan

Leave a comment