How to make two foreign keys to same model unique together?
Let's say I have a relationship class such as: class Friendship(models.Model): person1 = models.ForeignKey(Person, related_name='person1') person2 = models.ForeignKey(Person, related_name='person2') so I want to make this object unique for a pair of Person s. If I simply do unique_together = (("person1", "person2"),) then I can end up with two Friendship objects where FS1.person1 = A, FS1.person2 = B FS2.person1 = B, FS2.person2 = A I do not want this. I want a unique friendship object between two people. So how can I ensure that there is -at most- one Friendship object for any pair of Person