【Python】Django filter 如何支持 or 条件过滤?
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