I’m trying to make a simple ‘follow’ functionality in Django, like so (by the way, I’m not using django.contrib.auth, if that makes a difference):
class User(models.Model):
followers = models.ManyToManyField('self')
# rest of code
I’ve tested this out on my site with two users, User X and User Y…but when User X is added to User Y’s followers, User Y is also added to User X’s followers, which was not the intended outcome. How can I make this a one-sided relationship? Am I doing something wrong?
By default, a self referential
ManyToManyFieldis symmetrical. See the following in the docs:You can achieve it by adding:
models.ManyToManyField("self", symmetrical=False)