我找不到两个相关模型中哪一个应该具有 M2M 字段的逻辑?这是 Django 教程中的一个示例
class Person(models.Model):
name = models.CharField(max_length=128)
class Group(models.Model):
name = models.CharField(max_length=128)
members = models.ManyToManyField(Person, through='Membership')
class Membership(models.Model):
person = models.ForeignKey(Person)
group = models.ForeignKey(Group)
date_joined = models.DateField()
invite_reason = models.CharField(max_length=64)
如果我在 Person 而不是 Group 中定义 M2M 字段会有什么不同?
class Person(models.Model):
name = models.CharField(max_length=128)
groups = models.ManyToManyField(Person, through='Membership')
class Group(models.Model):
name = models.CharField(max_length=128)
class Membership(models.Model):
person = models.ForeignKey(Person)
group = models.ForeignKey(Group)
date_joined = models.DateField()
invite_reason = models.CharField(max_length=64)