title: Search and Retrieve the data from the database in Django
body: <p>I wanted to search and retrieve the data from the database in the Django I have saved the data which comes from the API endpoint to the database and have created few labels in the html based on which it will filter the matched data from the database</p>
  <p>It rather than searching the matched value but its adding another column with searched value.</p>
  <p>For instance: If I search &quot;vendorname&quot; as Pepsi it should reflect the table row which containing Pepsi rather than it creating another column with the value as Pepsi.</p>
  <p>I don't know where I'm going wrong. I have lot of columns from the database and 6 labels just I have added few only here. Thanks in Advance</p>
  <p>I have created two database here one for filter another for API data:</p>
  <p>models.py:</p>
  <pre><code>       //filter
         class Userbase(models.Model):
              Vendor_Name = models.CharField(max_length=255,  null=True)
              Region = MultiSelectField(choices=CHOICES)
               Area = MultiSelectField(choices=AREACHOICES)
      
       //api data
       class invoiceapi(models.Model):
             Vendor_Name = models.CharField(max_length=155, null=True)
             area = models.CharField(max_length=155, null=True)
             country = models.CharField(max_length=155, null=True)
  </code></pre>
  <p>views.py:</p>
  <pre><code>     def homeview(request):
            userb = Userbase.objects.all()
            table_data= requests.get('http://127.0.0.1:1500/api/').json() 
  
  
        if request.method == 'POST':
      
          userb = Userbase()
          userb.Area =  request.POST.getlist('Area')
          userb.country =  request.POST.getlist('country')
          userb.Vendor_Name =  request.POST.get('Vendor_Name')
          userb.save()
  
       #  api data saving in db
        for new_data in  table_data:
     
            data = {
              'area': new_data['area'],
              'country': new_data['country'],
              'VendorName': new_data['VendorName'],
                
              }
    
          user = invoiceapi.objects.create(**data)
          user.save()
       
       //search filter
        if request.method == 'POST':
       
          finder = request.POST['Vendor_Name']
          invoiceuser = invoiceapi.objects.filter(PBK_Desc__iexact=finder)
          print(invoiceuser)
          print(finder)
          return render(request, 'home.html',  
                                        {'userb':userb,'table_data':table_data,'finder':finder})
  
        return render(request, 'home.html', {'userb':userb,'table_data':table_data})
  </code></pre>
  <p>html:</p>
  <pre><code>    &lt;form action=&quot; &quot; method=&quot;POST&quot; autocomplete=&quot;off&quot;&gt;
          {% csrf_token %}
          &lt;div class=&quot;row&quot;&gt;
            &lt;div class=&quot;row&quot; id=&quot;row_id&quot;&gt;    
            &lt;br&gt;
  
            &lt;div style=&quot;margin-left: 19px; font-size: 17px;&quot;&gt;Payment Term&lt;/div&gt;
              &lt;div class=&quot;row&quot; id=&quot;id_row&quot;&gt;
                &lt;input type=&quot;text&quot; name=&quot;Vendor_Name&quot; maxlength=&quot;255&quot; class=&quot;form-control mb-3&quot;
                 style=&quot;margin-left: 30px; &quot; placeholder=&quot;Vendor_Name&quot; id=&quot;Vendor_Name&quot; required=&quot;&quot;&quot;&gt;
              &lt;/div&gt;  
              &lt;br&gt;
              &lt;br&gt;
  
            &lt;input type=&quot;submit&quot; value=&quot;Apply&quot; id=&quot;btn_submit&quot; style=&quot; width:90px; height:45px; margin-left: 40px; margin-bottom: 30px;&quot;
              class=&quot;btn btn-success btn&quot; &gt;
       
            &lt;input type=&quot;reset&quot; value=&quot;Reset&quot; id=&quot;btn_submit&quot; style=&quot; width:90px; height:45px;margin-left: 65px; margin-bottom: 30px;&quot;
              class=&quot;btn btn-success btn&quot;&gt;
            &lt;/div&gt;
          &lt;/form&gt;
        &lt;/div&gt;
      &lt;/div&gt;
  
  
      &lt;div class='container-l' id='table-wrapper' style=&quot;height:330px;width:100.5%; &quot;&gt;
        &lt;div id='container-table'style=&quot;height: 1050px;&quot;&gt;
  
          {% if userb %}
  
          &lt;table class=&quot;table table-striped border datatable&quot; id='table_id'&gt;
  
            &lt;thead&gt;
              &lt;thead id=&quot;tablehead&quot;&gt;
                &lt;tr&gt;  
                  &lt;th&gt; Area &lt;/th&gt;
                  &lt;th&gt; Country &lt;/th&gt;
                  &lt;th&gt; VendorName &lt;/th&gt;
                &lt;/tr&gt;
              &lt;/thead&gt;
            &lt;tbody&gt;
              {% for list in table_data %}
              &lt;tr&gt;   
                &lt;td&gt;{{list.area}}&lt;/td&gt;
                &lt;td&gt;{{list.country}}&lt;/td&gt;  
                &lt;td&gt;{{finder}}&lt;/td&gt;
              &lt;/tr&gt;
              {% endfor %}
     &lt;/tbody&gt;
     &lt;/table&gt;
     &lt;/body&gt;
     &lt;/div&gt; 
  {% endif %}
  </code></pre>