Created
December 22, 2011 21:12
-
-
Save marram/1511873 to your computer and use it in GitHub Desktop.
key names for picks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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