How to search for substring in textfield in a peewee query

Viewed 1068

I'm trying to return results that have a particular phrase or word in a textfield of a particular item in a Sqlite database using peewee.

My current attempt has been:

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)

Which returns the error: AttributeError: 'bool' object has no attribute 'clone'

For reference, this is the Pun model:

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

class Meta:
    database = db

Is this even the right way to go about searching for results in peewee?

Any help or pointing me in the right direction is massively appreciated!

1 Answers

EDIT: Use the query operators listed here, in particular .contains(substr)

ORIGINAL:

Use fn.substr, fn documentation is here.

A similar question and more thorough answer is here.

Related