首页 > 编程语言 > 详细

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

时间:2016-03-28 13:19:40      阅读:1806      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!