使用 django non-rel 在 GAE 上不区分大小写的 order_by

发布于 2024-09-28 19:17:41 字数 337 浏览 8 评论 0原文

使用谷歌应用程序引擎和 Django non-rel,我正在查询电影列表并希望按字母顺序对它们进行排序。

movies = Movie.objects.all().order_by("title")

问题是任何不以大写字符开头的标题不遵循相同的排序模式。

因此,如果查询这些电影并按顺序返回它们,那么“iRobot”将不会出现在蝙蝠侠和超级英雄之间:

  1. 世界末日
  2. 蝙蝠侠
  3. 超级英雄
  4. iRobot

如何让它们执行不区分大小写的 order_by?

谢谢

Using google app engine and Django non-rel, I'm querying a list of movies and want to order them alphabetically.

movies = Movie.objects.all().order_by("title")

The problem is for any titles that do not start with an uppercase character is not following the same sort pattern.

So if queried these movies and returned them sorted then "iRobot" would not be between Batman and Zoolander:

  1. Armageddon
  2. Batman
  3. Zoolander
  4. iRobot

How do I get them to do a case-insensitive order_by?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

空城仅有旧梦在 2024-10-05 19:17:41

您需要反规范化:存储一个包含小写版本标题的单独属性,并对其进行排序。

You need to denormalize: store a separate property that contains a lower-case version of the title, and sort on that.

不醒的梦 2024-10-05 19:17:41

也许您可以使用返回属性的小写版本的计算属性?

https://developers.google.com/appengine/docs/python/ndb /属性#计算

Maybe you can use a computed property that returns the lowercase version of your property?

https://developers.google.com/appengine/docs/python/ndb/properties#computed

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文