【发布时间】:2019-05-15 19:35:36
【问题描述】:
这是我的代码:
q = [
"78",
"95",
"77",
"91",
"92",
"93",
"94",
"75",
"27",
"28",
"45",
"89",
"10",
"51",
"02",
"60",
"27",
]
query = reduce(operator.and_, (Q(code_postal__startswith=item) for item in q))
result = Record14.objects.filter(query)
for r in result :
print(r)
我想要查询 Record14 中的所有对象,其中 code_postal 以 q 数组中的值开头。
我确定我的数据库中有数据,但查询为空...
我不明白为什么。
【问题讨论】:
-
您使用
and_作为reducer,这意味着您说:邮政编码应以78 开头,并且应以10 开头。任何文本不能同时以两者开头。
标签: python django django-queryset