title: How to update database value in django on a button click
body: <p>I have a template that contains one search button (this is for filtering the details based on option choose in the select) and a Next button (this is to move to next tab).</p>
  <p>When the template loads for then i will search for projects from the select list and the result will be displayed in a table - which is working for me.</p>
  <p>After the result is displayed in the table, i will select a row (through radio button) from that table and click on Next button to move to next tab. Here when i click the Next button i want to update some values in the django database but not able to achieve this. Can some one help me?</p>
  <p>My View:</p>
  <pre><code>def form(request):
      projects = CreateProjects.objects.filter(Status=True)
      if request.method == 'POST':
          selectproject = request.POST.get('selectproject')
          searchprojlist = ListProjDetails.objects.filter(Project=selectproject)
          return render(request,'form.html',{'projects':projects,'lists': searchprojlist})
      elif request.POST.get('tab1btn','') == 'nxttab':
          selval = ListProjDetails.objects.get(id=1)
          selval.Selected = True
          selval.LockedUser = request.user
          selval.save()
      else:
          lists = ListProjDetails.objects.all()
          return render(request,'form.html',{'projects':projects})
  </code></pre>
  <p>First If POST is working correctly, trouble is with the 2nd IF (2nd button). I have swapped the 2nd IF to be called fresh after the else statement but not working either.</p>
  <p>I have passed id=1 for testing purpose only</p>
  <p><a href="https://i.stack.imgur.com/C56Zd.jpg" rel="nofollow noreferrer">enter image description here</a></p>
  <p>I have added the image for better understanding, basically when the template loads select project from the list and <code>Search</code> and then choose one from the output and press <code>next</code> that moves to next tab by updating values like <code>select</code> to <code>True</code> and <code>Locked User</code> to <code>current user</code>.</p>
  <p>My view as explained before.</p>
  <p>My Javascript:</p>
  <pre><code>$(function(){
      $('#nexttab').click(function(e){
          e.preventDefault();
          if(document.getElementById('selectradio').checked){
                $('#tabs a[href=&quot;#tab2&quot;]').tab('show');
          }
      });
  })
  </code></pre>
  <p>Template:</p>
  <pre><code>&lt;form method=&quot;POST&quot;&gt;
                              {% csrf_token %}
                              &lt;div class=&quot;row ml-auto&quot;&gt;
                                  &lt;select class=&quot;custom-select mb-4 ml-2&quot; name=&quot;selectproject&quot; style=&quot;width: 30em;&quot;&gt;
                                      &lt;option selected&gt;Choose...&lt;/option&gt;
                                      {% for projects in projects %}
                                      &lt;option&gt;{{ projects.ProjName}}&lt;/option&gt;
                                      {% endfor %}
                                  &lt;/select&gt;
                                  &lt;div class=&quot;ml-4&quot;&gt;
                                      &lt;button type=&quot;submit&quot; class=&quot;btn btn-primary&quot; value=&quot;Search&quot;&gt;Search&lt;/button&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                              
                              &lt;table class=&quot;table&quot;&gt;
                                  &lt;thead class=&quot;thead-light&quot;&gt;
                                      &lt;tr&gt;
                                          &lt;th scope=&quot;col&quot; class=&quot;text-center&quot;&gt;S.No.&lt;/th&gt;
                                          &lt;th scope=&quot;col&quot; class=&quot;text-center&quot;&gt;Project Name&lt;/th&gt;
                                          &lt;th scope=&quot;col&quot; class=&quot;text-center&quot;&gt;Doc&lt;/th&gt;
                                          &lt;th scope=&quot;col&quot; class=&quot;text-center&quot;&gt;Target Date&lt;/th&gt;
                                          &lt;th scope=&quot;col&quot; class=&quot;text-center&quot;&gt;Docnum&lt;/th&gt;
                                          &lt;th scope=&quot;col&quot; class=&quot;text-center&quot;&gt;Type&lt;/th&gt;
                                          &lt;th scope=&quot;col&quot; class=&quot;text-center&quot;&gt;Select&lt;/th&gt;
                                          &lt;th scope=&quot;col&quot; class=&quot;text-center&quot;&gt;Locked by User&lt;/th&gt;
                                          &lt;th scope=&quot;col&quot; class=&quot;text-center&quot;&gt;Status&lt;/th&gt;
                                      &lt;/tr&gt;
                                  &lt;/thead&gt;
                                  &lt;tbody&gt;
                                      {% for lists in lists %}
                                      &lt;tr&gt;
                                          &lt;th scope=&quot;row&quot; class=&quot;text-center&quot;&gt;{{ lists.id }}&lt;/th&gt;
                                          &lt;td class=&quot;text-center&quot;&gt;{{ lists.Project }}&lt;/td&gt;
                                          &lt;td class=&quot;text-center&quot;&gt;{{ lists.doc }}&lt;/td&gt;
                                          &lt;td class=&quot;text-center&quot;&gt;{{ lists.TargetDate }}&lt;/td&gt;
                                          &lt;td class=&quot;text-center&quot;&gt;{{ lists.docnum }}&lt;/td&gt;
                                          &lt;td class=&quot;text-center&quot;&gt;{{ lists.type }}&lt;/td&gt;
                                          &lt;td class=&quot;text-center&quot;&gt;&lt;input class=&quot;form-check-input&quot; type=&quot;radio&quot;
                                                  name=&quot;select1&quot; id=&quot;selectradio&quot; value=&quot;option1&quot;&gt;&lt;/td&gt;
                                          &lt;td class=&quot;text-center&quot;&gt;{{ lists.LockedUser }}&lt;/td&gt;
                                          &lt;td class=&quot;text-center&quot;&gt;
                                              {% if lists.DStatus == &quot;Available&quot; %}
                                              &lt;label class=&quot;badge badge-success&quot;&gt;
                                                  {% else %}
                                                  &lt;label class=&quot;badge badge-warning&quot;&gt;
                                                      {% endif %}
                                                      {{ lists.DStatus }}&lt;/td&gt;
                                      &lt;/tr&gt;
                                      {% endfor %}
                                  &lt;/tbody&gt;
                              &lt;/table&gt;
                              &lt;div class=&quot;text-right mr-5&quot;&gt;
                                  &lt;button type=&quot;submit&quot; class=&quot;btn btn-primary&quot; id=&quot;nexttab&quot; name=&quot;tab1btn&quot;
                                      value=&quot;nxttab&quot;&gt;Next&lt;/button&gt;
                              &lt;/div&gt;
  
                          &lt;/form&gt;
  </code></pre>