简体   繁体   English

如果 MySQL 数据库中存在特定字段,则自动隐藏表的行/列使用 Django

[英]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.我正在做一个 Django 项目,我遇到了这样一种情况:如果特定实体存在于数据库的列中,我想隐藏表中的一行。 I am using MYSQL database.我正在使用 MYSQL 数据库。 I want auto hide row without clicking on any button or any checkbox.我想要自动隐藏行而不单击任何按钮或任何复选框。

page.html:第 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:意见.py:

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

models.py:模型.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条件是 if name == 'abc', 那么它应该在不点击任何按钮的情况下自动隐藏数据

In views.py you can use exclude so:views.py中你可以使用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" .这将不包括user = "abc"的特定数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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