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

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

问题描述

在 App Engine NDB 中,我正在查询具有重复属性的实体.我想按表示该属性的数组的长度对结果进行排序.

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.

我希望我能做什么:

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

推荐答案

您需要将 ndb.IntegerProperty() 添加到您的实体,您将在其中存储重复属性的长度.每次更改重复属性时,都需要更新存储的长度.然后根据存储的长度进行排序.

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天全站免登陆