使用PostgreSQL的Model方法,Django查询排序不区分大小写
发布时间:2020-12-13 16:29:49 所属栏目:百科 来源:网络整理
导读:我是django,python和postgres的新手……我似乎无法找到关于如何在使用Model作为查询方法时不区分大小写的order_by的答案,只有当你使用直接SQL查询时. Model@classmethoddef get_channel_list(cls,account): return cls.objects.filter(accountid=account).or
我是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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- oracle——distinct的用法
- redux在react-native上使用(三)--加入redux-thun
- ruby-on-rails – Ruby 1.9中的主要语法变化是什
- ruby-on-rails – 使用bootstrap模式的turbolink
- SQLite在android中的使用,以及常用增删查改的命
- objective-c – 如何将巨型项目Objective C转换为
- 我如何在C#中使用.NET的StreamWriter获得最佳性能
- ruby – Watir可以与Firefox Extensions交互吗?
- 关于RN listview item ref
- 仿百度文库方案[openoffice.org 3+swftools+flex
热点阅读