I have a django Model as follows:
class ModelName(models.Model):
field_one = models.ForeignKey(Table_One, related_name="field_one")
field_two = models.ForeignKey(Table_One, related_name="field_two")
I know unique_together
can be used to make sure duplicate entries cant be made.
Eg, if for the above table:
unique_together = ['field_one', 'field_two']
Then you can enter values such as A
for field_one
and B
for field_two
. However, you cannot make the same entry again. But this also allows entry B
for field_one
and A
for field_two
, which according to my controller logic is the same as A and B
.
I need to make sure that if A and B are entered for the respective fields, B and A cannot be entered again.
How do I allow only entries of unique combinations?