Performing Boolean Logic in views and template

am having two set of challenges. First, I have a model with field submit as Boolean field. I use model form and render it in template. There are two options as Boolean select i.e. 'Yes' and 'No' option for user to select whether he want to save the form or not. I want if this user select 'Yes', the form should be save. else if he select 'No', the form should not be save. I have exhausted all the logics that i thought could work but cannot achieve this. Below is the views

views.py

 def submit(request):
    if request.method =='POST':
        form = submitForm(request.POST)
        form.instance.user = request.user
        sub = form.save()
        if sub.sumit ==True:

        if sub:
            messages.info(request, 'You have submitted you form successfully')
            return redirect('home')
         
        messages.info(request, 'Continue editing your data')
        return render(request, 'portal/home/submit.html')
    form =submitForm()
    context = {
        'form':form,
        # 'sub':sub
    }
    return render(request, 'portal/home/submit.html', context)

my second question is in this view. since I could not achieve what i wanted in the above form, i just query it in this user_info so that if user save the submit as 'Yes' or 'No' some certain buttons in template should or should not show. below is how i try but not exactly what i wanted. i want only the user that select the above Boolean form as True or 'Yes' as shown on the template to not see the 'save' and 'Update' button but anyone that did not submit yet or submit 'No' can see all the buttons.

views

def user_info(request):

    # user = request.user
    user =request.user
    try:
        personal = Personalinfo.objects.get(user_id=user)
    except Personalinfo.DoesNotExist:
        messages.error(request, 'Please fill in all data')
        personal =None
    # try:
    sub = SubmitData.objects.filter(user_id = user)
    
    


    # except SubmitData.DoesNotExist:
        # messages.error(request, f'You already submitted you data on, {sub.date_submited}')
        # sub =None

    if request.method == "POST":
        form = usersForm(request.POST, request.FILES, instance =personal)
        if form.is_valid():
            form.instance.user = request.user
            form.save()          
            messages.success(request, 'User data saved successful! Click next to proceed')
            return redirect('user_info')
        
        else:
            messages.error(request, 'Error! Check your data')
            return redirect('user_info')
      
    form = usersForm(instance =personal)
    context={
        "form": form,
        'sub':sub,
        # 'submitted':submitted
        }
    return render(request, 'portal/home/user_info.html', context)

this the template

                      {% if sub %}
                      
                      <div class="col-md-4 col-sm-3">
                        <div class="text-center">
                          
                            <a class="btn btn-dark text-decoration-none text-white bg-dark mt-4 mb-0" href="{% url 'academy' %}">Next</a>      
                          
                        </div>
                      </div>
                    </div>
                      {% else %}

                      <div class="row">
                        <div class="col-md-10 col-sm-10 mx-auto ">
                          <button type="submit" name="register" class="text-white btn bg-dark mt-4 mb-0">
                            Save
                          </button>
                          <a class="btn btn-dark text-decoration-none text-white btn bg-dark mt-4 mb-0" href="{% url 'user_update' request.user.pk %}"> Update </a>      
                          
                          <a class="btn btn-dark text-decoration-none text-white bg-dark mt-4 mb-0" href="{% url 'academy' %}">Next</a>    
                        </div>
                        
                      </div>


                    {% endif %}
                    

Your answers will improve me alot. Thanks

First question:

I'm assuming the field is called sumit as per your question (apologies if this is a typo :-) )

Where you have

    form.instance.user = request.user
    sub = form.save()
    if sub.sumit ==True:

    if sub:
        messages.info(request, 'You have submitted you form successfully')
        return redirect('home')
     

replace with

    #set up sub as a 'falsey' value
    sub = ""
    #create an instance of form
    form = submitForm(request.POST)
    #check that the data is valid
    if form.is_valid():
        #check if the 'submit' checkbox has been checked
        #this is assuming you are using a default boolean checkbox widget, 
        #which only gets submitted if checked
        #with other widgets you might need to check for a particular value
        #eg, if form.cleaned_data.get("sumit") == "Yes"
        if form.cleaned_data.get("sumit"):
            form.instance.user = request.user
            sub = form.save()
        if sub:
            messages.info(request, 'You have submitted you form successfully')
            return redirect('home')
     

For the second question - if I've understood correctly, you should be able to do it with a further filter on sub so that the query is only successful if the user has indicated yes :

sub = SubmitData.objects.filter(user_id = user, sumit=True)
Back to Top