0

I have this and it works perfect

Model.name.startswith(name)

but i need this

name.startswith(Model.name)

Occurrence of a field value in a string. Thx

waynee
  • 117
  • 5
  • `Model.name` has no value: it described a field in your model. If you have a *specific instance* (that you got e.g. from a previous query) it makes sense to ask about the name. – larsks Sep 21 '20 at 12:42
  • i need something like this, but with peewee https://stackoverflow.com/questions/29389293/sql-query-to-find-if-a-string-contains-part-of-the-value-in-column – waynee Sep 21 '20 at 12:49

1 Answers1

1

Use Value(). Note that a wildcard is added

Model.select().where(Value(name).startswith(Model.name))

The corresponding SQL, approximately:

SELECT id, name
FROM model_tbl
WHERE '<value in name var>' LIKE (name || '%')
coleifer
  • 24,887
  • 6
  • 60
  • 75
  • thx it's great, but Value exist only from peewee 3 version? there is no alternative for the second version? – waynee Sep 28 '20 at 05:36