Django just keeps getting better and better.
I thought there would be hell to pay with admin form save overriding but it was surprisingly easy.
In the model you wish to enforce uniqueness, simply add a Meta class declaration and give it the property "unique_together".
1.
class
SomeModel(models.Model):
2.
class
Meta:
3.
unique_together
=
((
"fieldA"
,
"fieldB"
),)
4.
5.
fieldA
=
models.ForeignKey(BlahA)
6.
fieldB
=
models.ForeignKey(BlahB)
7.
8.
description
=
models.TextField()
Whalla! Now it will not let you add any rows which would break the "fieldA AND fieldB" uniqueness constraint.
The change is made at a database level so if data already exists you'll have to migrate the changes somehow.
[ Source ]