from operator import or_ from django.db.models import Q from functools import reduce filter_ip_list = ["不能为空"] # 排除 models.ServerHost.objects.filter(b_project_id=99).exclude(reduce(or_, (Q(host_ip=filter_ip) for filter_ip in filter_ip_list))) # 过滤 models.ServerHost.objects.filter(b_project_id=99).filter(reduce(or_, (Q(host_ip=filter_ip) for filter_ip in filter_ip_list)))
标签:models,ip,reduce,django,filter,list,字段,import From: https://www.cnblogs.com/chenjw-note/p/16792749.html