database - unique value field based on another field in django -


Introduction: I'm new to django and db design.

SUPEREDIT: I made some significant changes, so before my changes the answers can not be described here. I'm sorry.

I will inherit the code: models.py:

  class player (models.model): name = models.CharField () class team (Models.Model) : Name = models.CharField () member = models.ManyToManyField (player, = 'membership') class word (models.Model): word = models.CharField (unique = true) definition = models.CharField (). .. class ownership (models.Model): owner = model. Exotic (player) team = model. Foreign key (team) word = model. Foreign Key (Word) class membership (models.Model): team = models.ForeignKey (Team) Player = Model. Forwardkey (player)  

The word table has populated. I make a player in the admin. Then I join the members by creating a team. I have added ownership to the administrator. I create a new proprietorship and I have to choose from players, teams, and words. I want to put an obstacle where a player is the owner of a word for a team, then that team Players concerned can not get the word within the team. They can be the master of the word in other teams.

The way in which it is now I could have two different players of the same team near the same word, poorly. Actually, I want the administrator to take all the words owned by this team and do not make them available in the drop down.

How can I make this relationship a model? How can I get this functionality in admin?

EDIT: I just added the membership model to show that I am trying to solve a different problem. And as I said, this is a simple example of who I am actually working with. As you can see that I have a membership relationship, I am trying to solve a different problem of ownership.

Your schema is incorrect You should use "additional area on multiple-to-many relationships".

For my "team-number" association, I am not sure that it will work in conjunction with additional areas on many different perspectives. Otherwise, you can apply uniqueness in this view, but I believe that unique_togaster should work in your case.

For the range of 1-99, you only need to complete it with your form verification, and in combination with a specificity check, you do not need the entire table to store the number 1-99.

Update for your edit

I'm not sure you can actually read my post or follow any of my links, but this solves the problem you describe Of course, unless you have not understood this problem properly, you should not express some modeling of "ownership" of a number, you should express it where it is related:

  class Player (Model Model): name = models.CharField (max_le Ngth = 128) Def __unicode __ (self): returns self-name class team (model. Model): name = model. Kharifield (max_long = 128) players = models. Majority (player, = 'membership') def __unicode __ (self): return Self.name class membership (models.Model): player = models.ForeignKey (player) team = models.ForeignKey (team) number = models IntegerField () "" ... ... "" Category Meta: unique_together = ('Team', 'Number')  

Please tell me again that player-team-number Why do you need a proprietary model for the associations, because I'm not sure what you are actually doing to get it, which I already have Donation is different from that.


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -