Relationships Among These Models In Django
I want to build a website where: there is a set of 10 Cards on each Card, there are Important/Not_Important/Unknown attributes each User chooses which card are important and not i
Solution 1:
I guess I have found the solution to my question: The models would be like this :
class Card(models.Model):
card_number = models.IntegerField(unique=True)
content = models.TextField(null=False)
class Choice(models.Model):
user= models.ForeignKey(User)
card = models.ForeignKey(Card)
is_important = models.NullBooleanField(default=None)
class Meta:
unique_together = ('user','card')
The key to the answer is to use unique_together Meta option.
Please review my solution and if you have a better solution or any alternative solution, please feel free to suggest. I can learn a lot from yours.
Thanks!
Post a Comment for "Relationships Among These Models In Django"