Created
August 5, 2012 07:28
-
-
Save colinpollock/3262624 to your computer and use it in GitHub Desktop.
Tastypie: model and resource for Player
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 Player(models.Model): | |
name = models.CharField(primary_key=True, max_length=50) | |
date_added = models.DateTimeField('date added', default=datetime.now()) | |
rating = models.IntegerField(default=1600) | |
@property | |
def wins(self): | |
return self.winner_games.all() | |
@property | |
def num_wins(self): | |
return self.winner_games.count() | |
@property | |
def losses(self): | |
return self.loser_games.all() | |
@property | |
def num_losses(self): | |
return self.loser_games.count() | |
def __unicode__(self): | |
return self.name | |
class PlayerResource(ModelResource): | |
class Meta: | |
queryset = Player.objects.all() | |
resource_name = 'player' | |
authorization = Authorization() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment