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")
Comments
Post a Comment