NDB:对查询结果进行排序 [英] NDB: Sort query results

查看:131
本文介绍了NDB:对查询结果进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在App Engine NDB中,我正在查询具有重复属性的实体。我希望通过表示该属性的数组的长度来命令结果。



我希望我能做的事情:

  Entity.query(...)。order(len(Entity.repeatedProp))

$您需要为您的实体添加一个 ndb.IntegerProperty(),您可以在其中添加

将存储重复属性的长度。每次改变重复属性时,都需要更新存储的长度。然后你根据存储的长度进行排序。

你可以使用计算属性,但我从来没有使用过其中的一个,所以我不确定。

p>

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:

Entity.query(...).order(len(Entity.repeatedProp))

解决方案

You'll need to add an 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.

You could probably use a computed property, but I've never used one of those so I'm not sure.

这篇关于NDB:对查询结果进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆