首页 > 其他 > 详细

Django 模糊查询

时间:2016-06-30 16:22:05      阅读:126      评论:0      收藏:0      [点我收藏+]

 

官方文档地址

https://docs.djangoproject.com/en/1.8/topics/db/queries/#complex-lookups-with-q-objects

 

F查询

 

contains查询

Entry.objects.get(headline__contains=‘Lennon‘)
Roughly translates to this SQL:
SELECT ... WHERE headline LIKE ‘%Lennon%‘;

icontains查询

q.exclude(body_text__icontains="food")

exact   查询

Entry.objects.get(headline__exact="Man bites dog")

iexact查询
Blog.objects.get(name__iexact="beatles blog")

Q查询:

from django.db.models import Q
Q(question__startswith=‘What‘)


Q(question__startswith=‘Who‘) | Q(question__startswith=‘What‘)
This is equivalent to the following SQL WHERE clause:

WHERE question LIKE ‘Who%‘ OR question LIKE ‘What%‘


Q(question__startswith=‘Who‘) | ~Q(pub_date__year=2005)


Poll.objects.get(
    Q(question__startswith=‘Who‘),
    Q(pub_date=date(2005, 5, 2)) | Q(pub_date=date(2005, 5, 6))
)
... roughly translates into the SQL:

SELECT * from polls WHERE question LIKE ‘Who%‘
    AND (pub_date = ‘2005-05-02‘ OR pub_date = ‘2005-05-06‘)

Django 模糊查询

原文:http://www.cnblogs.com/schangech/p/5630178.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!