0
多対多の関係を持つことができるDjangoモデルを作成しようとしています。多対多の関係を持つことができるDjangoモデルを作成する
これは私のmodels.pyです:
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.',
)
私はmanage.py makemigrations
を実行すると、私はこれが可能である私に言うと、それを行う方法を教えてください、次のエラー
<class 'appsrfun.admin.SimilarAppsInline'>: (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'.
を取得します。おかげ
変更 'SimilarApps'' MySimilarApps'(私は変更のモデル名を意味する) – itzMEonTV
はちょうどそれを試したと私は同じを取得しますエラー – HenryM