I am using Google App Engine to build a web game. The game has a list of stored user-created levels (which may be a lot, and dynamically increasing as well), and each user has a list of levels which he has played already. I need to randomly pick up a level for a user which he has not played before. The Entities are modeled like this:
class User(ndb.Model):
uid = ndb.StringProperty()
levels_played = ndb.KeyProperty(kind='Level', repeated=True)
class Level(ndb.Model):
#some stuff here
So basically I need to perform a query which, given a uid
, chooses a random Level which does not belong to the corresponding list levels_played
. What would be the most efficient way to do this?