i am currently playing with django and i want to model a simple relation: two members of a dance-club should be paired as a dancing couple in order to participate in a dancing-tournament. I already have a simple model for the members:
class Member(models.Model):
firstname = models.CharField(max_length=32)
lastname = models.CharField(max_length=32)
member_id = models.IntegerField(unique=True)
def __unicode__(self):
return self.firstname + ' ' + self.lastname
I also have a tournament Model:
class Tournament(models.Model):
name = models.CharField(max_length=32)
def __unicode__(self):
return self.firstname + ' ' + self.lastname
Since a participant in a tournament is a couple i need to define a couple-relation (at least that would be my guess). But i really don’t get how i’d do that.
tia for any help and tips
You could maybe try defining a model called something like Couple, and two foreign key relationships to the the Member table, with a relationship to the Tournament they are in:
I’m not sure of your requirements, but the way I presented allows members to be part of multiple couples, and a couple is unique to a tournament. Depending on how you want do it, you may want to have couples to be fixed (i.e Stacey and Bob always dance together). In that case you would probably want to have a many-to-many relationship from Tournament to couple:
So a couple can be in many tournaments, and a tournament can have many couples.