如何在 peewee 查询的文本字段中搜索子字符串

How to search for substring in textfield in a peewee query

我正在尝试 return 使用 peewee 在 Sqlite 数据库中特定项目的文本字段中包含特定短语或单词的结果。

我目前的尝试是:

for key in listOfKeys:
    foundPun = models.Pun.select().where(key in str(models.Pun.keywords)).get()
    click.echo('-'*10)
    click.echo(foundPun.pun)
    click.echo('-'*10)

哪个 return 错误: AttributeError: 'bool' object has no attribute 'clone'

供参考,这是双关模型:

class Pun(Model):
    pun = TextField()
    keywords = TextField(default="")
    tags = TextField(default="")

class Meta:
    database = db

这是在 peewee 中搜索结果的正确方法吗?

非常感谢任何帮助或为我指明正确的方向!

编辑: 使用列出的查询运算符 here,特别是 .contains(substr)

原创:

使用fn.substrfn文档是here

类似的问题和更彻底的答案是