[Answered ]-Error accesing reverse manytomany field from user to onetoone related model

1👍

✅

The ForeignKey fields in through models need to reference the model that contains the ManyToManyField and not the model in the OneToOneField – UserInteraction and not User

class UserFollow(TimeStampBase):
    follower = models.ForeignKey(UserInteraction, on_delete=models.CASCADE, related_name='follower')
    followed = models.ForeignKey(UserInteraction, on_delete=models.CASCADE, related_name='followed')
    ...

class UserLike(TimeStampBase):
    liker = models.ForeignKey(UserInteraction, on_delete=models.CASCADE, related_name='liker')
    liked = models.ForeignKey(UserInteraction, on_delete=models.CASCADE, related_name='liked')
    ...

Leave a comment