I have the following in my app:
class University(models.Model):
...
sister_university = models.OneToOneField('self', related_name =
'university_sister_university',
blank=True, null=True,
on_delete=models.SET_NULL)
I only want a university to be related to one other university in both directions of that relationship.
For example, in the database, if I select university A as the sister_university of university B, I only want to be allowed to select university B as the sister_university under university A also. However, as it is, that second relationship is not enforced.
For example: Right now, under the Django Admin site, if I first select university A as the sister university of university B, I am still able to select any other university as the sister university of the university A object. I’m not constrained to only selecting university B.
Is it possible to enforce that uniqueness at the database level? Is there a better way of accomplishing what I’m trying to do?