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

Tom*_*ill 5 python sqlite python-3.x peewee

我正在尝试使用 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)
Run Code Online (Sandbox Code Playgroud)

返回错误: AttributeError: 'bool' object has no attribute 'clone'

作为参考,这是双关语模型:

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

class Meta:
    database = db
Run Code Online (Sandbox Code Playgroud)

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

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

tha*_*vik 3

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

原来的:

使用fn.substrfn文档在这里

类似的问题和更彻底的答案在这里