Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

In views.py you can use exclude:

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading