NDB: Sort query results

可紊 提交于 2019-12-12 15:25:19

问题


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))

回答1:


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.




回答2:


Depending on how many entities are you sorting you can sort it by code.



来源:https://stackoverflow.com/questions/32567628/ndb-sort-query-results

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!