Django self referential m2m field causes causes missing attribtue error
<p>I get an error if I try to make a self-referential m2m Field. Am I missing something here?</p>

<pre><code>class UserProfile(models.Model):
    following = models.ManyToManyField('self', related_name='followers')
</code></pre>

<p>somewhere else in a serializer:</p>

<pre><code>def get_followers(user):
    return user.profile.followers

AttributeError: 'UserProfile' object has no attribute 'followers'
</code></pre>

<p>Is there another way I can implement followers? Maybe I should make another model to do this or use a library?</p>

<p>By default, Django treats all <code>self</code> m2m relations as symmetrical, for example if I am your friend, you are my friend too. When relation is symmetrical, Django won't create reverse relation attribute to your model.</p>

<p>If you want to define non-symmetrical relation, set <code>symmetrical=False</code> attribute on your field, example:</p>

<pre><code>    following = models.ManyToManyField('self', related_name='followers', symmetrical=False)
</code></pre>

<p>More on that in <a href="https://docs.djangoproject.com/en/1.10/ref/models/fields/#django.db.models.ManyToManyField.symmetrical" rel="nofollow">Django documentation</a></p>

python django django-models many-to-many