5👍
✅
You have to set in the Meta class in the KeyList:
class KeyList(models.Model):
key_one = models.ForeignKey(KeyOne)
key_two = models.ForeignKey(KeyTwo)
key_three = models.ForeignKey(KeyThree)
list = models.CharField()
class Meta:
unique_together = (("key_one", "key_two", "key_three"),)
👤bcap
11👍
Django > 2.2
Use UniqueConstraint with the constraints option instead.
UniqueConstraint provides more functionality than unique_together. unique_together may be deprecated in the future.
So in your case:
class KeyList(models.Model):
key_one = models.ForeignKey(KeyOne)
key_two = models.ForeignKey(KeyTwo)
key_three = models.ForeignKey(KeyThree)
list = models.CharField()
class Meta:
constraints = [
models.UniqueConstraint(fields=["key_one", "key_two", "key_three"], name="all_keys_unique_together")
]
- [Django]-What is the settings for django rest framework swagger open api security object definition for oauth2 flow being password?
- [Django]-Django-compressor: disable caching using precompilers
- [Django]-Posting complex data dictionary with request python
- [Django]-How can I tell if a value is a string or a list in Django templates?
- [Django]-Editing models and extending database structure in Saleor
Source:stackexchange.com