在PostgreSQL中使用Model方法的Django Query排序不区分大小写
发布于 2021-01-29 14:10:43
我真的是django,python和postgres的新手…仅在使用直接SQL查询的情况下,使用Model作为查询方法时不区分大小写,我似乎无法找到关于order_order的答案。
Model
@classmethod
def get_channel_list(cls, account):
return cls.objects.filter(accountid=account).order_by('-name').values_list('name', 'channelid')
数据集和排序,目前正在订购中
test
b test
a test channel
a test channel
a test 2
a b test
Test Channel
Test 3
Test 3
Test 2 Channel
任何帮助将非常感激。
关注者
0
被浏览
99
1 个回答
-
@classmethod def get_channel_list(cls, account): ret = cls.objects.extra(select={'name_lower': 'lower(name)'}) ret = ret.order_by('-name_lower') ret = ret.filter(accountid=account).values_list('name', 'channelid') return channels