python - Django Queryset for substr matching that starts from the beginning of a string -


i have model word, every instance of model stores word or phrase in a field called text. e.g.,
"matches"
"match"
"match sticks"
"matching"
"notmatch"

now want construct django queryset such given query, want find words contains query substring starts beginning. example, if query match:
"matches" - yes, contains match substring starts beginning
"match sticks" - yes, similar above
"notmatch" - no, because substring doesn't start beginning

i can't use "contain" field lookup directly because doesn't match beginning. use "contain" manually filter results, there more efficient way. what's efficient way of doing this?

use startswith match string start:

model.objects.filter(text__startswith="match") 

django doc startswith.


Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -