manytomany relationships between the same two tables in this example a person can have many friends who are also person objects friendship is a symmetrical relationship if i am your friend you are my friend here friends is an example of a symmetrical manytomanyfield a person can also have many idols but while i may idolize you you may not think the same of me here idols is an example of a nonsymmetrical manytomanyfield only recursive manytomanyfield fields may be nonsymmetrical and they are symmetrical by default this test validates that the manytomany table is created using a mangled name if there is a name clash and tests that symmetry is preserved where appropriate
from django.db import models


class Person(models.Model):
    name = models.CharField(max_length=20)
    friends = models.ManyToManyField("self")
    colleagues = models.ManyToManyField("self", symmetrical=True, through="Colleague")
    idols = models.ManyToManyField("self", symmetrical=False, related_name="stalkers")

    def __str__(self):
        return self.name


class Colleague(models.Model):
    first = models.ForeignKey(Person, models.CASCADE)
    second = models.ForeignKey(Person, models.CASCADE, related_name="+")
    first_meet = models.DateField()