Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your schema is incorrect. You should be making use of "Extra fields on Many-to-Many relationships" <a href="http://docs.djangoproject.com/en/dev/topics/db/models/#extra-fields-on-many-to-many-relationships" rel="nofollow noreferrer">as seen here in the Django docs</a>.</p> <p><a href="https://stackoverflow.com/questions/72945/how-to-create-a-triple-join-table-with-django">It is also highlighted here on SO.</a></p> <p><a href="http://docs.djangoproject.com/en/dev/ref/models/options/#unique-together" rel="nofollow noreferrer">Look into <code>unique_together</code></a> for your "team-number" association. I'm not sure if it will also work in conjunction with the extra fields on the many-to-many approach. Otherwise, you could enforce the uniqueness in the view, but I do believe <code>unique_together</code> should work in your case.</p> <p>For the 1-99 limitation, you should just include this in your form validation, and in conjunction with a uniqueness check, you do not need an entire table just to store the numbers 1-99.</p> <h2>Update for your edit</h2> <p>I'm not sure you actually read my post or followed any of my links but it solves exactly the problem you described, unless of course you still haven't explained the problem correctly. "Ownership" of a number is not something you should be modeling, you should be expressing it where it belongs:</p> <pre><code>class Player(models.Model): name = models.CharField(max_length=128) def __unicode__(self): return self.name class Team(models.Model): name = models.CharField(max_length=128) players = models.ManyToManyField(Player, through='Membership') def __unicode__(self): return self.name class Membership(models.Model): player = models.ForeignKey(Player) team = models.ForeignKey(Team) number = models.IntegerField() """ ... """ class Meta: unique_together = ('team', 'number') </code></pre> <p>So please explain to me again how you need an Ownership model for Player-Team-Number associations, because I'm not sure what exactly you're trying to achieve that is separate from what I already provided you.</p>
    singulars
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      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