我是django,python和postgres的新手……我似乎无法找到关于如何在使用Model作为查询方法时不区分大小写的order_by的答案,只有当你使用直接SQL查询时.
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
任何帮助将非常感激.
使用
QuerySet.extra(select=...)
:
@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
原文地址:https://www.jb51.cc/postgresql/192766.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。