【问题标题】:Google App Engine - ndb sorting by string? (Python)Google App Engine - ndb 按字符串排序? (Python)
【发布时间】:2013-07-18 04:59:14
【问题描述】:

是否可以按StringProperty对查询结果进行排序?

我有以下几点:

class User(ndb.Model):
     first_name = ndb.StringProperty(indexed=False)
     last_name = ndb.StringProperty(indexed=False)

现在,如果我想从数据库中检索存储的条目,我会使用这个(它有效):

user_query = User.query(ancestor=user_key(user_name))

但我希望结果按名字排序,所以我使用这个:

user_query = User.query(ancestor=user_key(user_name)).order(-User.first_name)

这不起作用!我不知道出了什么问题,它不会产生任何错误,但不再显示任何结果。我得到的只是一张空桌子:-(

【问题讨论】:

    标签: python database google-app-engine app-engine-ndb


    【解决方案1】:

    你需要一个索引才能工作。

    【讨论】:

    • 谢谢!令人沮丧的是没有抛出错误,没有索引的订单只是默默地不返回任何内容......
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-27
    • 1970-01-01
    相关资源
    最近更新 更多