问题描述
在Google App Engine的ndb上,我使用以下命令检索所有实体并根据其级别对其进行排序:
排名= Member.query()。order(-Member.grade)
然后我想知道特定成员的位置:
i = 0
用于排名:
如果rank.account =='abc'
position = i
break
i + = 1
我的问题:是否有一个等价的ndb操作来查找特定实体的位置?感谢。
我相信这可以分两步完成
-
检索帐户为'abc'的条目
target = Member.query(Member.account =='abc') .get()
-
.grade> target.grade).count()
然后你得到目标的等级为n + 1
On Google App Engine's ndb, I used the following to retrieve all entities and sort them according to their grade:
ranks = Member.query().order(-Member.grade)
Then I would like to know the position of a specific member:
i = 0
for rank in ranks:
if rank.account == 'abc'
position = i
break
i += 1
My question: is there an equivalent ndb operation to find the position of a specific entity? Thanks.
I believe it could be done in two steps
Retrieve the entry whose account is 'abc'
target = Member.query(Member.account=='abc').get()
Query for entries with higher grade
n = Member.query(Member.grade>target.grade).count()
Then you get target's rank as n+1
这篇关于Google App Engine ndb:找到订单查询列表的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!