В Django модели у меня есть 6 вопросов, если пользователь ответил на 5 вопросов и отправил, он должен сохранить 5 значений в базе данных, пока что мой код не сохраняет их.

def api_page(request):

    if request.method == "POST":
        if request.POST.get('q34_employeeId') and request.POST.get('q37_domain') and request.POST.get('q35_howLong') and request.POST.get('q103_typeA') and request.POST.get('q104_howSatisfied') and request.POST.get('q105_howSatisfied105') and request.POST.get('q106_howSatisfied106') and request.POST.get('q89_typeA89'):
            post = Employee()
            post.Employee_ID = request.POST.get('q34_employeeId')
            post.Domain = request.POST.get('q37_domain')
            post.Working_years = request.POST.get('q35_howLong')
            post.Satisfied_with_company = request.POST.get('q103_typeA')
            post.Satisfied_with_manager = request.POST.get('q104_howSatisfied')
            post.Satisfied_with_management = request.POST.get('q105_howSatisfied105')
            post.Satisfied_with_HR = request.POST.get('q106_howSatisfied106')
            post.Overall_experience = request.POST.get('q89_typeA89')
            sc=Employee.objects.filter(Employee_ID=post.Employee_ID)
            if sc.count() > 0:
                Employee.objects.filter(Employee_ID=post.Employee_ID).update(Domain=post.Domain, Working_years=post.Working_years,Satisfied_with_company=post.Satisfied_with_company,Satisfied_with_manager=post.Satisfied_with_manager,Satisfied_with_management=post.Satisfied_with_management,Satisfied_with_HR=post.Satisfied_with_HR,Overall_experience=post.Overall_experience)
            elif post.Overall_experience:
                post.save()
            elif not post.Overall_experience:
                post.save(update_fields=[post.Employee_ID,post.Domain,post.Working_years,
                post.Satisfied_with_company,post.Satisfied_with_manager,post.Satisfied_with_management,post.Satisfied_with_HR])
            return HttpResponseRedirect('success/')

Вот мой вышеприведенный код, который я пробовал, если пользователь отправляет 5 вопросов, он не сохраняется в базе данных, но когда пользователь отправляет все 6 вопросов, он добавляется в базу данных.

Пожалуйста, помогите с этим, заранее спасибо

Вернуться на верх