更新时间:2023-02-18 23:23:52
我认为可能有一个更好的方式来做到这一点与Django查询系统。以下是如何做到这一点。
I think there may be a better way to do this with the Django query system. Here's how to do it your way.
Python允许您通过将其作为参数列表使用**作为参数列表。
有一个运气的地方,你应该能够这样做:
Python allows you to pass dictionaries to be used as argument lists by prefixing them with **. With a spot of luck, you should be able to do something like this:
lookup = "%s__contains" % field
results.append(Item.objects.filter(**{ lookup: keyword}))