开发者

Case-insensitive order_by on GAE using django non-rel

Using google a开发者_开发知识库pp 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


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


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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜