利用django的Q()功能可以很好的展开搜索功能

假设我要做个这样的搜索功能

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAYQAAACwCAIAAACAQ46LAAAgAElEQVR4nO2d/1Mb1733949Ihh+cmcw4P3TuM52p8+RO5fQHyEwjOdO6pSmJ3eLYDuDBpJPGbpqK22RsdcZ21bnKDImUmNrYBYe2cusg3Vs/mKYh43bkREaKTYFg8GX67Ao5CNC3lXYlgckjPT+cs2fPrnZXXxAg7M8rB2n3nM/5nM9nV+ets8viMP/933/589B/9fUPXoACZWNKX//g4B///LtLf9jySKDUZ7n6f/56e/yfzOrq/VX0s7q6unr/PvpZXSUb0huqvE9a5Y73qSZ6X+FPGoOMRAa6v6och/SRGpAJ7XWV3r8vv92nR6Cjg9QgNUitflP76quv1tbWmJXV1dWV1dXV1dWVVby9Qiqk6hXyJtWiphXSe4VqXZG94a0VyRi7QmayweoqqS1C4YjqhSOgQlqhA6JjgdQgNUit/lNjVlDgiFX8s7KygvOiqsgQlO0q2SR9yPuq3EQZSJvEWN6QQpF3FTu0Q3rsVUW7ygWkBqlBatskNWZlZSWXW1nJraysoNdcLreSw5VoC1WvEAtpC/XL5VZy2GYll5OdoU45ym0ul8vh4SQfUnc8KHYq+VfGJI8jhUZ65JAJiZYMs87UVigll44q+RqQN6VzsbqyQsn9Kjl7UgfF147cGRuSbxR5m3yk5K8aMgyJRnaDK1fk7yXyPUZ9960Qz5AapFZPqTFIInIUih2duhVdK416LdPqjGTbFd0gVL6qTy2bzQYCgaGhIbfb7b6Mf1RoVFVpJNuioXQ6XdbZ1rRX12l7hdRKhlOGLaS2/tSYbC6bzeZyuWw2l0PbWWk7l8tlc7kcrsjlstgyR1qz6B11z2az2WyOOMB1OeI/K3XMEsuc4h17yuHRs7hTNicVZCkNnJXGkSLOynZZKZFqU8vlchP/nPj0009XVlYKAABsPExWiwz1o9Wm2sroGKirdVr0+5SwLNrOZLLZjFSt7bPM1FZWVnw+3+rq6lafIAB4WGAymWwGkc1m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BgBwLqAiVMrQIwAYF3AxKkVIEYAsC5g4tQKECMAWBcwcWoFiBEArAuYOLUCxAgA1gVMnFoBYgQA6wImTq0AMQKAdQETp1ZoiBEUKFCqKFs4jR8MQIygQKlN2cJp/GAAYgQFSm3KFk7jB4MK/m+iAAAAGweIEQAAdQGIEQAAdQGIEQAAdQGIEQAAdQGIEQAAdQGIEQAAdQGIEQAAdQGIEQAAdQGIEQAAdQGIEQAAdQGIEQAAdQGIEQAAdQGIEQAAdQGIEQAAdQGIEQAAdQGIEQAAdQGIEQAAdQGIEQAAdQGIEQAAdcH/Bxt9MXR933zZAAAAAElFTkSuQmCC" alt="" />

那么思路是怎么样的?

前端获取 --》输入 --》ajax后台获取 --》进行搜索  --》将值返回后台  ---》ajax在进行处理传到页面

那我们就来看看代码

前端的代码:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.left{
float: left;
}
.clearfix:after{
content: '.';
clear: both;
display: block;
visibility: hidden;
height: 0;
}
</style>
</head>
<body>
<div class="condition">
<div class="item clearfix">
<div class="icon left" onclick="AddCondition(this);">+</div>
<div class="left">
<select onchange="ChangeName(this);">
<option value="name">书名</option>
<option value="book_type__caption">图书类型</option>
<option value="price">价格</option>
<option value="pages">页数</option>
</select>
</div>
<div class="left"><input type="text" name="name" /></div>
</div>
</div>
<div>
<input type="button" onclick="Search();" value="搜索" />
</div>
<div class="container"></div>
<script src="/static/js/jquery-1.12.4.js"></script>
<script>
function AddCondition(ths) {
var new_tag = $(ths).parent().clone();//克隆
new_tag.find('.icon').text('-'); //更改+ 为-
new_tag.find('.icon').attr('onclick', 'RemoveCondition(this);'); //属性什么等于什么 $(ths).parent().parent().append(new_tag);//添加
}
function RemoveCondition(ths) {//删除
$(ths).parent().remove();
}
function ChangeName(ths) {//改变名称就触发
var v = $(ths).val();//得到值
$(ths).parent().next().find('input').attr('name',v);//改变属性name的值为v
}
function Search() {
var post_data_dict = {};//定义一个{} // 获取所有input的内容,提交数据
$('.condition input').each(function () {//循环
// console.log($(this)[0])
var n = $(this).attr('name');//得到属性值
var v = $(this).val();//得到val值
var v_list = v.split(',');//,分割
post_data_dict[n] = v_list;//定义一个列表
});
console.log(post_data_dict);
var post_data_str = JSON.stringify(post_data_dict);
$.ajax({
url: '/app03/index/',
type: 'POST',
data: { 'post_data': post_data_str},
dataType: 'json',

前端代码1——发送数据

                success: function (arg) {
// 字符串 "<table>" +
if(arg.status){
var table = document.createElement('table');
table.setAttribute('border',1);
// [{,name,pubdate,price,caption},]
$.each(arg.data, function(k,v){
var tr = document.createElement('tr'); var td1 = document.createElement('td');
td1.innerText = v['name'];
var td2 = document.createElement('td');
td2.innerText = v['price'];
var td3 = document.createElement('td');
td3.innerText = v['book_type__caption'];
var td4 = document.createElement('td');
td4.innerText = v['pubdate'];
tr.appendChild(td1);
tr.appendChild(td2);
tr.appendChild(td3);
tr.appendChild(td4); table.appendChild(tr);
}); $('.container').empty();
$('.container').append(table);
}else{
alert(arg.message);
} } })
}
</script>
</body>
</html>

前端接受并处理数据2

后端的代码:

import json
from datetime import date
from datetime import datetime
from decimal import Decimal
class JsonCustomEncoder(json.JSONEncoder): def default(self, field): if isinstance(field, datetime):
return field.strftime('%Y-%m-%d %H:%M:%S')
elif isinstance(field, date):
return field.strftime('%Y-%m-%d')
elif isinstance(field, Decimal):
return str(field)
else:
return json.JSONEncoder.default(self, field)
def index(request):
if request.method == 'POST':
ret = {'status': False, 'message': '', 'data':None}
try:
post_data = request.POST.get('post_data',None)
post_data_dict = json.loads(post_data)
print(post_data_dict)
# {'name': ['11', 'sdf'],'price': ['11', 'sdf']}
# 构造搜索条件
from django.db.models import Q
con = Q()
for k,v in post_data_dict.items():
q = Q()
q.connector = 'OR'
for item in v:
q.children.append((k, item))
con.add(q, 'AND')
""" ret = models.Book.objects.filter(con)
print(ret) # queryset,[对象] #就是上面是列表 from django.core import serializers
#这种方法是django的自己的序列化方法,但是有个缺点,下面这句的ret只能是对象,所以只能用第二种方式
data = serializers.serialize("json", ret)
print(type(data),data)
# 字符串
"""
"""
#ret = models.Book.objects.filter(con).values('name','book_type__caption')
ret = models.Book.objects.filter(con).values_list('name', 'book_typ__ecaption')
print(ret,type(ret))
li = list(ret)
#这种方式也有一个缺点,就是date和小数的时候不能序列化,所以需要自定义类并继承
data = json.dumps(li)
print(data,type(data))
"""
print(type(con))
result = models.Book.objects.filter(con).values('name','price','pubdate','book_type__caption')
# ret = models.Book.objects.filter(con).values_list('name', 'book_type__caption')
li = list(result)
ret['status'] = True
ret['data'] = li
except Exception as e:
ret['message'] = str(e)
ret_str = json.dumps(ret, cls=JsonCustomEncoder)
return HttpResponse(ret_str)
return render(request, 'input.html')

views

django的前后的结合,search搜索功能案例的更多相关文章

  1. Django之使用haystack+whoosh实现搜索功能

    为了实现项目中的搜索功能,我们使用的是全文检索框架haystack+搜索引擎whoosh+中文分词包jieba 安装和配置 安装所需包 pip install django-haystack pip ...

  2. 【起航计划 032】2015 起航计划 Android APIDemo的魔鬼步伐 31 App->Search->Invoke Search 搜索功能 Search Dialog SearchView SearchRecentSuggestions

    Search (搜索)是Android平台的一个核心功能之一,用户可以在手机搜索在线的或是本地的信息.Android平台为所有需要提供搜索或是查询功能的应用提 供了一个统一的Search Framew ...

  3. search搜索功能

    1.html <div class="search">        <form name="formsearch" action=" ...

  4. 使用ajax实现搜索功能

      最近要做一个搜索功能,网上搜了一圈,终于做出来了,很简单的一个,这里分享我的方法,希望对大家有用,不足之处还请指教. 这里使用ajax提交数据,配合jquery将数据显示出来. 用jq的keyup ...

  5. 第三百六十九节,Python分布式爬虫打造搜索引擎Scrapy精讲—elasticsearch(搜索引擎)用Django实现搜索功能

    第三百六十九节,Python分布式爬虫打造搜索引擎Scrapy精讲—elasticsearch(搜索引擎)用Django实现搜索功能 Django实现搜索功能 1.在Django配置搜索结果页的路由映 ...

  6. 四十八 Python分布式爬虫打造搜索引擎Scrapy精讲—elasticsearch(搜索引擎)用Django实现搜索功能

    Django实现搜索功能 1.在Django配置搜索结果页的路由映射 """pachong URL Configuration The `urlpatterns` lis ...

  7. 011.Adding Search to an ASP.NET Core MVC app --【给程序添加搜索功能】

    Adding Search to an ASP.NET Core MVC app 给程序添加搜索功能 2017-3-7 7 分钟阅读时长 作者 本文内容 1.Adding Search by genr ...

  8. Django项目实战 - 搜索功能(转)

    首先,前端已实现搜索功能页面, 我们直接写后台逻辑: Q()可以实现 逻辑或的判断,   name_ _ icontains 表示 name字段包含搜索的内容,i表示忽略大小写. from djang ...

  9. Django 建立用户的视图(搜索 )

    在web应用上,有两个关于搜索获得巨大成功的故事:Google和Yahoo,通过搜索,他们建立了几十亿美元的业务.几乎每个网站都有很大的比例访问量来自这两个搜索引擎.甚至,一个网站是否成功取决于其站内 ...

随机推荐

  1. JavaWeb学习笔记——开发动态WEB资源(二)HelloWord

    该工程的功能是在页面上输出一段话 首先在src里面新建一个class,在interface里面添加javax.servlet.Servlet 以下是HelloServlet.java中的代码: pac ...

  2. iTunes访问自己应用的沙盒

  3. JAVA Applet

  4. Linux基础整理-软件的安装与卸载

    redhat/centos/fedora/suse系列: 摘自网址:http://www.runoob.com/linux/linux-yum.html yum( Yellow dog Updater ...

  5. Lua与C的交互

    Lua 与 C 的交互 Lua是一个嵌入式的语言,它不仅可以是一个独立运行的程序,也可以是一个用来嵌入其它应用的程序库. C API是一个C代码与Lua进行交互的函数集,它由以下几部分构成: 1.  ...

  6. Yii2.0-生成二维码实例

    原文地址:http://www.yii-china.com/post/detail/19.html

  7. Mac按键

    ⌘——Command ⌃ ——Control ⌥——Option (alt) ⇧——Shift ⇪——Caps Lock ⌫——Delete

  8. 巧用svn create patch(打补丁)方案解决定制版需求

    最近项目定制版越来越多,维护,同步代码非常费事.以前的思路如下图: 以前的svn目录结构如下图: 这样问题有2个: 若在一个定制包中修复了其他定制包也有的bug,同步更新其他包的代码时,非常费劲+机械 ...

  9. Oracle的DBMS_OUTPUT.PUT_LINE用法及脚本批处理方法

    打印至控制台(无显示): BEGIN DBMS_OUTPUT.PUT_LINE('Hey look, ma!'); END; / 打印至控制台(有显示): SET SERVEROUTPUT ON BE ...

  10. [C#]通用守护进程服务

    摘要 很多情况下,都会使用windows服务做一些任务,但总会有一些异常,导致服务停止.这个时候,开发人员又不能立马解决问题,所以做一个守护者服务还是很有必要的.当检测到服务停止了,重启一下服务,等开 ...