Skip to content

Instantly share code, notes, and snippets.

@colinpollock
Created August 5, 2012 07:28
Show Gist options
  • Save colinpollock/3262624 to your computer and use it in GitHub Desktop.
Save colinpollock/3262624 to your computer and use it in GitHub Desktop.
Tastypie: model and resource for Player
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