NDB:对查询结果进行排序 [英] NDB: Sort query results
问题描述
在App Engine NDB中,我正在查询具有重复属性的实体。我希望通过表示该属性的数组的长度来命令结果。
我希望我能做的事情:
Entity.query(...)。order(len(Entity.repeatedProp))
$您需要为您的实体添加一个 你可以使用计算属性,但我从来没有使用过其中的一个,所以我不确定。 In App Engine NDB, I am querying entities that have a repeated property. I would like to order the result by the length of the array representing that property. What I wish I could do:
You'll need to add an You could probably use a computed property, but I've never used one of those so I'm not sure. 这篇关于NDB:对查询结果进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! ndb.IntegerProperty()
,您可以在其中添加
Entity.query(...).order(len(Entity.repeatedProp))
ndb.IntegerProperty()
to your entity where you will store the length of the repeated property. Every time you change your repeated property, you'll need to update the stored length. Then you sort based on that stored length.