0
說我在谷歌App Engine的數據存儲以下模型:谷歌App Engine的資料儲存庫查詢和獲取相對排名
class Post(ndb.Model):
name = ndb.StringProperty()
votes = ndb.IntegerPropery()
我想先查詢後得到的選票數量排序的所有帖子(最高到最低),然後找到名稱爲「John」的郵政排名/地點。 因此,如果約翰郵政獲得第二票數,他將在第二名。
有沒有簡單的方法來做到這一點? 現在我做這樣的事情:
posts = Post.query().order(-Post.votes)
for post, index in enumerate(posts):
if post.name == "John":
print(index)
我想這是不是要做到這一點非常好/有效的方式。