【发布时间】:2012-03-15 01:22:15
【问题描述】:
我有一些递归 Django ManytoManyField,它们在我的应用程序中使用“通过属性”。这是一个例子:
class Author(models.Model):
user = models.OneToOneField(User, parent_link=True)
introduction = models.TextField(blank=True)
pictures = models.ManyToManyField('Graphic', related_name='users', null=True)
organizations = models.ManyToManyField('Organization', related_name='members')
expertise = models.ManyToManyField('Tag', related_name='experts', null=True)
interests = models.ManyToManyField('Tag', related_name='interested_in', null=True)
saved_articles = models.ManyToManyField(Article, related_name='favorited_by', null=True, through='SavedArticles')
authors_followed = models.ManyToManyField('self', related_name='authors_followed', null=True, through='FollowedAuthors', symmetrical=False)
class FollowedAuthors(models.Model):
author = models.ForeignKey(Author)
trustee = models.ForeignKey(Author)
notes = models.TextField()
tags = models.ManyToManyField('Tag')
我知道我可以访问 MyAuthor.authors_followed.all(),但是如果我想调用 FollowedAuthor.authors_followed.all() 来返回 MyAuthor,我不能只使用 related_name='authors_followed' 吗?这是否只是否定了symmetric=False 行为?
here 提出了类似的问题,但在这种情况下,他们有:
recursive_field = models.ManyToManyField('self', through='ThroughTable', related_name='different_field').
我是否缺少对对称和相关名称工作原理的一些了解?
【问题讨论】:
标签: django django-models