How to specify uniqueness for a tuple of field in a Django model
This video explains
How to specify uniqueness for a tuple of field in a Django model
--
Become part of the top 3% of the developers by applying to Toptal
https://topt.al/25cXVn
--
Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Game 5
--
Chapters
00:00 Question
00:31 Accepted answer (Score 42)
00:53 Thank you
--
Full question
https://stackoverflow.com/questions/4723...
Accepted answer links:
[documentation]: http://docs.djangoproject.com/en/dev/ref...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #django #djangomodels
#avk47
How to specify uniqueness for a tuple of field in a Django model
--
Become part of the top 3% of the developers by applying to Toptal
https://topt.al/25cXVn
--
Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Game 5
--
Chapters
00:00 Question
00:31 Accepted answer (Score 42)
00:53 Thank you
--
Full question
https://stackoverflow.com/questions/4723...
Accepted answer links:
[documentation]: http://docs.djangoproject.com/en/dev/ref...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #django #djangomodels
#avk47
ACCEPTED ANSWER
Score 42
There is a META option called unique_together. For example:
class MyModel(models.Model):
field1 = models.BlahField()
field2 = models.FooField()
field3 = models.BazField()
class Meta:
unique_together = ("field1", "field2")
More info on the Django documentation page.