How to prevent many-to-many class to link to the same objects?
<p>In my User model, I've specified this:</p>

<pre><code>friends = models.ManyToManyField(
    'self', 
    blank=True, 
    symmetrical=False, 
    through='Relationship')
</code></pre>

<p>And here's that class I'm using:</p>

<pre><code>class Relationship(models.Model):
    person1 = models.ForeignKey(
        User, 
        on_delete=models.CASCADE, 
        related_name="person1")

    person2 = models.ForeignKey(
        User, 
        on_delete=models.CASCADE, 
        related_name="person2")
        is_active = models.BooleanField(default=False)

    class Meta:
        unique_together = (('person1', 'person2'),)
</code></pre>

<p>With <code>unique_together</code> I've tried to make many-to-many relations to be one-directional i.e. to prevent creating many-to-many object if the same object with specified keys exist in vice-versa order, but it doesn't work. Also it seems that the relation can't be symmetrical because if I set that attribute to true it's giving me an error which says that with custom class isn't possible.<br>
There's one more thing I wanted to do - prevent creation of a m2m object with foreign keys which are both the same. When searching over the Internet I've found the part of Django documentation which talks about <a href="https://docs.djangoproject.com/en/dev/topics/db/models/#overriding-predefined-model-methods" rel="nofollow">overriding model functions</a>, so if I go by that method the result would be:</p>

<pre><code>def save(self, *args, **kwargs):
    if self.person1 == self.person2:
        return
    else:
        super().save(*args, **kwargs)
</code></pre>

<p>My questions are following: Can someone help me with creating symmetrical relation, and is this method above good, or there's some better way to achieve that?</p>