Skip to content

Instantly share code, notes, and snippets.

@Attila03
Created September 1, 2017 17:09
Show Gist options
  • Save Attila03/ca669e781f22e6f05a8a228363b5cc2b to your computer and use it in GitHub Desktop.
Save Attila03/ca669e781f22e6f05a8a228363b5cc2b to your computer and use it in GitHub Desktop.
class Match(models.Model):
WHITE = 'White',
BLACK = 'Black',
DRAW = 'Draw',
UNDETERMINED = 'Undetermined'
MATCH_RESULT_CHOICES = (
(WHITE, 'White Won'),
(BLACK, 'Black Won'),
(DRAW, 'Draw'),
(UNDETERMINED, 'Undetermined')
)
round = models.ForeignKey('Round')
players = models.ManyToManyField('Player', through='PlayerColor')
result = models.CharField(max_length=20, choices=MATCH_RESULT_CHOICES, default=UNDETERMINED)
# def __str__(self):
# return "{} vs {} - {}".format(self.white_player, self.black_player, self.result)
class PlayerColor(models.Model):
WHITE = 'White'
BLACK = 'Black'
COLOR_CHOICES = (
(WHITE, 'White'),
(BLACK, 'Black')
)
player = models.ForeignKey('Player')
match = models.ForeignKey('Match')
color = models.CharField(max_length=10, choices=COLOR_CHOICES)
# ALTERNATE CHOICE
class Match(models.Model):
....
white_player = models.ForeignKey('Player', related_name='match_as_white_player')
black_player = models.ForeignKey('Player', related_name='match_as_black_player')
....
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment