简体   繁体   中英

Auto hide Row / Column of Table if specific field exists in MySQL Database using Django

I am working on a Django project and I am stuck in a situation where I want to hide a row in a table if specific entity exists in column in database. I am using MYSQL database. I want auto hide row without clicking on any button or any checkbox.

page.html:

<table border="2">
      <tr>
        <th> ID</th>
        <th> NAME</th>
        <th> PASSWORD</th>
        <th> IP</th>
        <th>PORT</th>
      </tr>

      {% for data in Cvs_logs %}
      <tr>
        <td>{{data.id}}</td>
        <td>{{data.user}}</td>
        <td>{{data.pass}}</td>
        <td>{{data.ip}}</td>
        <td>{{data.port}}</td>
      </tr>
      {% endfor %}
    </table>

views.py:

def home_view(request):
  auth = Cvs_logs.objects.all()
  return render(request, 'page.html', {'Cvs_logs': auth })

models.py:

class Cvs_logs(models.Model):
  id = models.BigIntegerField
  ip = models.CharField(max_length= 100)
  port = models.CharField(max_length= 100)
  user = models.CharField(max_length= 100)
  pass = models.CharField(max_length= 100)

  class Meta:
    db_table = "xyz"

The condition is if name == 'abc', then It should hide data automatically without clicking on any button

In views.py you can use exclude so:

def home_view(request):
  auth = Cvs_logs.objects.exclude(user="abc") #here
  return render(request, 'page.html', {'Cvs_logs': auth })

This will not include the specific data with user = "abc" .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM