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

Time:11-17

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

CodePudding user response:

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".

  • Related