开发者

Django query order depending on starts_with and contains

开发者 https://www.devze.com 2023-04-11 04:15 出处:网络
I try to make a special contains filter in django such that, if items are cba, abc, abd etc.. and if I want to get 开发者_StackOverflow中文版the items that contains ab,

I try to make a special contains filter in django such that,

the list should be ordered as abc,bca because abc starts with ab even though they both contains ab.

How can I make such query in django effectively ?

My query is at below

EmployerIndexed.objects.filter(name__icontains=empkw)


If I understand what you're asking, you want an alphabetical sort?

EmployerIndexed.objects.filter(name__icontains=empkw).order_by('name')
0

精彩评论

暂无评论...
验证码 换一张
取 消