qs.filter(name__contains="e")
qs.filter(name__icontains="e")
对应sql
'contains': 'LIKE BINARY %s',
'icontains': 'LIKE %s',
其中的BINARY是 精确大小写
而’icontains’中的’i’表示忽略大小写
开发项目中用到的
return_info = dict()
q_obj = Q()
q_obj.connector = 'OR'
for x in search_cols:
q_obj.children.append((x + "__icontains", keyword))
q_objs = (q_obj,) if keyword else tuple()
filters = filters if filters else dict()
country_datas = country_dal.get_infos_dict(
q_objs=q_objs,
filters=filters,
order_by=order_by,
values=values
)
if country_datas is not None:
page_helper = PageHelper(obj_list=country_datas, page=page, page_size=page_size)
common_datas = page_helper.get_object_list()
return_info["status"] = True
return_info["data"] = common_datas
return_info["page"] = page_helper.get_number() # 当前页码
return_info["page_count"] = page_helper.get_num_pages() # 总共分页数
else:
return_info["status"] = False
return_info["failed_data"] = "请求参数错误 关键词:%s 关键字匹配列表:%s 查询条件列表:%s 排序列表:%s 数据列表:%s" \
% (str(keyword), str(search_cols), str(filters), str(order_by), str(values))