Preface: I am new to django and to db design.
SUPEREDIT: I made some significant changes, so the answers before my changes may reference things not here. I apologize.
I'll get right to the code: models.py:
class Player(models.Model):
name = models.CharField()
class Team(models.Model):
name = models.CharField()
members = models.ManyToManyField(Player, through='Membership')
class Word(models.Model):
word = models.CharField(unique=True)
definition = models.CharField()
...
class Ownership(models.Model):
owner = models.ForeignKey(Player)
team = models.ForeignKey(Team)
word = models.ForeignKey(Word)
class Membership(models.Model):
team = models.ForeignKey(Team)
player = models.ForeignKey(Player)
the Word table has been populated. In the admin I create a Player. I then create a team and add members to it. I've added Ownership to the admin. I create a new Ownership and I get to pick from players, from the teams, and from the words. I'd like to put a constraint where if a player owns a word for a given team, then players belonging to that team can not own the word within the team. They may own the word in other teams.
The way it is now. I could have two different players on the same team own the same word. Bad. Basically I want the admin to say take all of the words owned within this team and not make them available in the drop down.
How can I model this relationship? How can I get this functionality in the admin?
EDIT: I added the membership model just to show that I am trying to solve a different problem. And as I said, this is a simplified example of what I am really working with. As you can see I've got the membership relationship done, I am trying to solve a separate problem of ownership.