目标实现:
我想要名称属性包含列表中任何单词的所有对象。
我有:
list = ['word1','word2','word3']
ob_list = data.objects.filter( // What to write here ? )
// or any other way to get the objects where any word in list is contained, in
// the na-me attribute of data.
例如:
if name="this is word2":
由于 word2 在列表中,因此应返回具有此类名称的对象。
请帮忙!
原文由 Yugal Jindle 发布,翻译遵循 CC BY-SA 4.0 许可协议
您可以使用
Q
对象 来构建这样的查询:编辑:
是一种奇特的写作方式
您还可以使用显式 for 循环来构造
Q
对象。