码迷,mamicode.com
首页 > 编程语言 > 详细

【Python】Django filter 如何支持 or 条件过滤?

时间:2016-03-28 13:21:28      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:

from django.db.models import Q

Item.objects.filter(Q(creator=owner) | Q(moderated=False))

代码示例:

if(request.GET.has_key(search)):
                search = request.GET.get(search)
                logger.info(search)
                from django.db.models import Q
                jobs_set = models.Deploy.objects.filter(Q(deployName__contains=search) | Q(submit__contains=search)).order_by(order_by)[offset:offset+limit]
                total = models.Deploy.objects.filter(Q(deployName__contains=search) | Q(submit__contains=search)).count()
            else:
                logger.info("NOSEARCH")
                jobs_set = models.Deploy.objects.all().order_by(order_by)[offset:offset+limit]
                total = models.Deploy.objects.count()

 

参考资料:

http://stackoverflow.com/questions/739776/django-filters-or

 

【Python】Django filter 如何支持 or 条件过滤?

标签:

原文地址:http://www.cnblogs.com/junneyang/p/5328527.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!