Creating a Django model that can have a many-to-many relationship with itself
<p>I'm trying to write a Django model that can have a many-to-many relationship with itself.</p>

<p>This is my <strong>models.py</strong>:</p>

<pre><code>class Apps(models.Model):
    name = models.CharField(
        verbose_name = 'App Name',
        max_length = 30
    )
    logo = models.ImageField(
        verbose_name = 'Logo'
        )
    description = models.TextField(
        verbose_name = 'Description'
    )
    google_url = models.URLField(
        verbose_name = 'Google Play Link',
        null = True
    )
    apple_url = models.URLField(
        verbose_name = 'Apple AppStore Link',
        null = True
    )
    youtube_url = models.URLField(
        verbose_name = 'Youtube Video Page',
        null = True
    )
    similar_apps = models.ManyToManyField(
        'self',
        through         = 'SimilarApps',
        related_name    = 'similar_apps',
        verbose_name    = 'Similar Apps',
        help_text       = 'Similar Apps',
        symmetrical     = False
        )

    def __unicode__(self):
        return u'%s' % (self.user.name)

class SimilarApps(models.Model):
    primary = models.ForeignKey(
        Apps,
        verbose_name    = 'Primary App',
        related_name    = 'primary_app',
        help_text       = 'First of 2 similar Apps.',
    )
    secondary = models.ForeignKey(
        Apps,
        verbose_name    = 'Matched App',
        related_name    = 'matched_app',
        help_text       = 'Second of 2 similar Apps.',
    ) 
</code></pre>

<p>When I run <code>manage.py makemigrations</code> I get the following error</p>

<pre><code>&lt;class 'appsrfun.admin.SimilarAppsInline'&gt;: (admin.E202) 'appsrfun.SimilarApps' has more than one ForeignKey to 'appsrfun.Apps'.
appsrfun.Apps.similar_apps: (fields.E302) Reverse accessor for 'Apps.similar_apps' clashes with field name 'Apps.similar_apps'.
    HINT: Rename field 'Apps.similar_apps', or add/change a related_name argument to the definition for field 'Apps.similar_apps'.
appsrfun.Apps.similar_apps: (fields.E303) Reverse query name for 'Apps.similar_apps' clashes with field name 'Apps.similar_apps'.
    HINT: Rename field 'Apps.similar_apps', or add/change a related_name argument to the definition for field 'Apps.similar_apps'.
</code></pre>

<p>Please tell me this is possible and explain how to do it.  Thanks</p>

<p>This has just got through <code>makemigrations</code> and I'm going to test it:</p>

<pre><code>class App(models.Model):
    name = models.CharField(
        verbose_name    = 'App Name',
        max_length      = 30
    )
    logo = models.ImageField(
        verbose_name    = 'Logo'
        )
    description = models.TextField(
        verbose_name    = 'Description'
    )
    google_url = models.URLField(
        verbose_name    = 'Google Play Link',
        null            = True
    )
    apple_url = models.URLField(
        verbose_name    = 'Apple AppStore Link',
        null            = True
    )
    youtube_url = models.URLField(
        verbose_name    = 'Youtube Video Page',
        null            = True
    )
    similar_app = models.ManyToManyField(
        'self',
        through         = 'MySimilarApp',
        verbose_name    = 'Similar App',
        help_text       = 'Similar App',
        symmetrical     = False,
        through_fields  = ('primary','secondary'),
        )

    def __unicode__(self):
        return u'%s' % (self.user.name)

class MySimilarApp(models.Model):
    primary = models.ForeignKey(
        App,
        verbose_name    = 'Primary App',
        related_name    = 'primary_app',
        help_text       = 'First of 2 similar Apps.',
    )
    secondary = models.ForeignKey(
        App,
        verbose_name    = 'Matched App',
        related_name    = 'matched_app',
        help_text       = 'Second of 2 similar Apps.',
    )       
</code></pre>

python django