In Django models I have 6 question, if user answered 5 questions and submitted it should save 5 values in database as of now my code is not saving ito
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/')
Here is my above code I have tried with if user submit with 5 questions it is not saving in database but when user submit all 6 questions it is adding to database.
Please help with this, Thanks in advance