阅读背景:

在Django中,通过相同的中间模型,两个许多与同一模型的任意关系

来源:互联网 

My models:

我的模型:

class Person(SchoolModel):
    first_name = models.CharField(max_length=75)
    last_surname = models.CharField(max_length=75)

    students = models.ManyToManyField('self', through='StudentParent',
        through_fields=('parent', 'student'), related_name='+')
    parents = models.ManyToManyField('self', through='StudentParent',
        through_fields=('student', 'parent'), related_name='+')


class StudentParent(SchoolModel):
    student = models.ForeignKey('Person')
    parent = models.ForeignKey('Person')
    relation = models.CharField(max_length=26)

    class Meta:
        unique_together = ('student', 'parent')
class Person(SchoolModel):



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: