<!-- 定制模糊搜索 开始 -->
{% if cl.search_list %}
<div class="row">
<form action="">
<input type="text" name="{{ cl.search_attr.name }}" value="{{ cl.search_attr.value }}" class="form-control"
style="display: inline-block;width: 250px" placeholder="请输入关键字">
<button type="submit" class="btn btn-primary">
<span class="glyphicon glyphicon-search"></span>
</button>
</form>
</div>
{% endif %}
<!-- 定制模糊搜索 结束 -->
@property
def search_condition(self):
"""获取模糊搜索条件"""
con = Q()
con.connector = "OR"
val = self.request.GET.get(self.q)
if not val:
return con
for k in self.get_search_list():
k="%s__contains"%k
con.children.append((k,val))
return con
data_list = self.model_class.objects.filter(**self.filter_condition).filter(self.search_condition).distinct()
search_list=[]
def get_search_list(self):
"""获取搜索的列,即将会在数据库的哪些列中搜索这些信息"""
search_list = []
search_list.extend(self.search_list)
return search_list