Django ManyToManyField:如何选择它的位置?

时间:2017-12-01 11:07:32

标签: django many-to-many

我对django中的ManyToManyField有两种可能性:

将它放在“父”类中:

from django.db import models

class Person(models.Model):
    pass

class Group(models.Model):
    members = models.ManyToManyField(Person, related_name='group')

将其放入“子”类

from django.db import models

class Group(models.Model):
    pass

class Person(models.Model):
    groups = models.ManyToManyField(Group, related_name='members')

这两个选项有什么区别?
是否有理由让一方优先于另一方?

0 个答案:

没有答案