Say I have the following model in Google App Engine's datastore:
class Post(ndb.Model):
name = ndb.StringProperty()
votes = ndb.IntegerPropery()
I want to first query Post to get all posts ordered by number of votes (highest to lowest) and then find the ranking/place of the Post with name "John". So if the Post by John has the 2nd most votes, he would be in 2nd place.
Is there an easy way to do this? Right now I'm doing something like:
posts = Post.query().order(-Post.votes)
for post, index in enumerate(posts):
if post.name == "John":
print(index)
I imagine this is not a very good/efficient way to do this.