python - Google App Engine: how to tell sort location for a user value? -
in main model have total_value , sort value. when user enters value wish tell user order of total_value. how do this?
in other words, if total_values in database 5,8,10,25 , user enters total_value of 15 how tell him in 4th place?
thanks!
you need write query counts number of values smaller user's total_value. may slow if there many main entities. in case, may wish count first n values smaller, , stop (e.g., tell user ranked 1000+). query might this:
# rank of total_value compared existing total_values (up 1,000) rank = main.all().filter('total_value <', total_value).count(1000) + 1
Comments
Post a Comment