查询在详细视图中

时间:2018-05-21 05:28:52

标签: django django-views

以表格形式显示详细视图。我想写一个搜索查询,显示找到的结果。数据以表格形式显示,并在顶部进行搜索。 ClientInfo是包含客户端所有信息的表。

Models.py

class ClientInfo(models.Model):
    client = models.ForeignKey(Clients, on_delete=models.CASCADE)
    insurance_name = models.CharField(max_length=250)
    cpt_code = models.CharField(max_length=100)
    subject = models.CharField(max_length=250)
    update = models.CharField(max_length=10000)
    date = models.DateTimeField(auto_now_add=True)
    update_date = models.DateTimeField(auto_now=True)
    update_by = models.CharField(max_length=250)

Detail.html

<table class="table table-bordered table-hover">

<tr>
    <th scope="col"><small>INCURANCE NAME</small></th>
    <th scope="col"><small>CPT-CODE</small></th>
    <th scope="col"><small>SUBJECT</small></th>
    <th scope="col"><small>UPDATE</small></th>
    <th scope="col"><small> DATE</small> </th>
    <th scope="col"><small> UPDATE DATE</small> </th>
    <th scope="col"><small> UPDATED BY</small> </th>
    <th scope="col"><small>Edit</small></th>
 </tr>
</thead>
<tbody>
 <tr>
   {% for item in client.clientinfo_set.all %}
    <td><small> {{ item.insurance_name }}</small></td>
    <td><small>{{ item.cpt_code }}</small></td>
  <td><small> {{ item.subject }}</small></td>
    <td><small><p>{{ item.update }}</p></small></td>
    <td><small><p>{{ item.date }}</p></small></td>
    <td><small>{{ item.update_date }}</small></td>
    <td><small>{{ item.update_by }}</small></td>
    <td><small></small><a href="">Edit Info</a></td>

  </tr>
  <br>
  {% endfor %}
  </tbody>

view.py

class IndexView(generic.ListView):
    template_name = 'update/index.html'
    context_object_name = 'all_client'
    def get_queryset(self):
        return Clients.objects.all()

class DetailView(generic.DetailView):
    context_object_name = 'client'
    model = Clients
    template_name = 'update/detail.html'

class ClientCreate(CreateView):
    model = Clients
    fields = '__all__'
    class ClientInfoCreate(CreateView):
    model = ClientInfo
    fields = '__all__'

class ClientUpdate(UpdateView):
    model = Clients
    fields = '__all__'

class ClientInfoUpdate(UpdateView):
    model = ClientInfo
    fields = '__all__'

class searchClientInfo(generic.DeleteView):
    model = ClientInfo
    template_name = 'update:detail'

    def get_context_data(self, **kwargs):
        context = 
        return context

我想检索与搜索用户放入搜索框

匹配的任何行

0 个答案:

没有答案