2017-06-19 67 views
0

我在我的模型一個問題,因爲我有一個多對多的關係循環引用Django的:多對多循環引用

這是我的web應用程序的一部分,該會議是一組(一組可以有多個會話),並且每個環節都不止一個助手,但助手只能是會議的小組成員

這裏是我的模型:

class GroupMember(models.Model): 
    member = models.ForeignKey(Volunteer, null=True, blank=True) 
    group = models.ForeignKey(Group) 
    leader = models.BooleanField(default=False) 
    created = models.DateTimeField(auto_now_add=True) 

    def __str__(self): 
     return '{}'.format(self.member) 

class Session(models.Model): 
    name = models.CharField(max_length=250) 
    group = models.ForeignKey(Group) 
    assistants = models.ManyToManyField(GroupMember,through=SessionAssistant) 
    created = models.DateTimeField(auto_now_add=True) 

    def __str__(self): 
     return '{}'.format(self.name) 

class SessionAssistant(models.Model): 
    assistant = models.ForeignKey(GroupMember) 
    session = models.ForeignKey(Session, null=True, blank=True, on_delete=models.CASCADE) 
    assist = models.BooleanField(default=True) 
    ability = models.IntegerField(null=True, 
           blank=True, 
           validators=[MaxValueValidator(5), MinValueValidator(1)]) 
    performance = models.IntegerField(null=True, 
            blank=True, 
            validators=[MaxValueValidator(5), MinValueValidator(1)]) 
    created = models.DateTimeField(auto_now_add=True) 

    def __str__(self): 
     return '{}'.format(self.assistant) 
+0

我們可以得到追溯 – DragonBobZ

回答

0

如果你改變assistants = models.ManyToManyField(GroupMember,through=SessionAssistant)到會發生什麼assistants = models.ManyToManyField(GroupMember,through='SessionAssistant')

+0

謝謝,我沒有看到我沒有'',現在的作品 –