Note that there are some explanatory texts on larger screens.

plurals
  1. POunique value field based on another field in django
    primarykey
    data
    text
    <p>Preface: I am new to django and to db design.</p> <p>SUPEREDIT: I made some significant changes, so the answers before my changes may reference things not here. I apologize.</p> <p>I'll get right to the code: models.py:</p> <pre><code>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) </code></pre> <p>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.</p> <p>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.</p> <p>How can I model this relationship? How can I get this functionality in the admin?</p> <p>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.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload