0
的獨特組合,我有4個Django模型:Django的外鍵
class KeyOne(models.Model):
name = models.CharField(unique=True)
class KeyTwo(models.Model):
name = models.CharField(unique=True)
class KeyThree(models.Model):
name = models.CharField(unique=True)
class KeyList(models.Model):
key_one = models.ForeignKey(KeyOne)
key_two = models.ForeignKey(KeyTwo)
key_three = models.ForeignKey(KeyThree)
list = models.CharField()
基本上,KeyList
是的KeyOne
,KeyTwo
和KeyThree
不同組合相關的關鍵字的列表。我如何確保在Django Admin中只能輸入獨特的組合?
嘗試用['unique_together'](https://docs.djangoproject.com/en/1.8/ref/models/options/ #獨一無二的)在類Meta:中。 – dhke