Skip to content

Instantly share code, notes, and snippets.

@marram
Created December 22, 2011 21:12
Show Gist options
  • Save marram/1511873 to your computer and use it in GitHub Desktop.
Save marram/1511873 to your computer and use it in GitHub Desktop.
key names for picks
class Pick(db.Model):
# Models a user's prediction of which team will win a game.
user = db.ReferenceProperty(User)
game = db.ReferenceProperty(Game)
picked_team = db.ReferenceProperty(Team)
@classmethod
def make_key_name(cls, user, game):
user_key = str(user.key())
game_key = str(game.key())
return "%s_%s" % (user_key, game_key)
def __init__(self, *args, **kwargs):
# A trick to inject a key_name into the default constructor.
if not kwargs.has_key('key') and not kwargs.has_key('key_name'):
key_name = self.__class__.make_key_name(kwargs['user'], kwargs['game'])
kwargs['key_name'] = key_name
db.Model.__init__(self, *args, **kwargs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment