Django ManyToMany self relationship with through model — user_from and user_to reversed behavior

I added following and followers by using intermediate model, it`s ok but does not correctly specify objects in the intermediate model. I expect the user who follows must to be in the user_from field and the one who followed to be in the user_to. but there are placed opposite. for example:

class User(AbstractUser):
    #somefields
    following = models.ManyToManyField("self", related_name='followers', through="Contact", through_fields=('user_to', 'user_from'), symmetrical=False,  blank=True)

intermediate model:

class Contact(models.Model):
    user_from = models.ForeignKey(User, related_name="rel_from_set", on_delete=models.CASCADE)
    user_to = models.ForeignKey(User, related_name="rel_to_set", on_delete=models.CASCADE)
    created = models.DateTimeField(auto_now_add=True)

    class Meta:
        ordering = ['-created']
        indexes = [models.Index(fields=['created'])]

    def __str__(self):
        return f"{self.user_from} follows {self.user_to}"
Вернуться на верх