django models 过滤/排除指定字段的多个值
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)))
一些事情一直在干,说不定以后就结果了呢
本文来自博客园,作者:chenjianwen,转载请注明原文链接:https://www.cnblogs.com/chenjw-note/p/16792749.html