0
我在萬畝型號:選擇模板的父母外鍵
class Profile(models.Model):
user = models.OneToOneField(User, blank=True, null=True)
phone_number = models.CharField(max_length=20, blank=True, null=True)
company = models.ForeignKey(Company, on_delete=models.CASCADE)
is_administrator = models.BooleanField(default=False)
def __str__(self):
return '{0}\'s profile'.format(self.user.username)
class Company(models.Model):
created_date = models.DateTimeField(default=timezone.now, null=True)
name = models.CharField(max_length=200)
class Invitation(models.Model):
created_date = models.DateTimeField(default=timezone.now, null=True)
date = models.ManyToManyField(Date)
speaker = models.ForeignKey(Speaker, on_delete=models.CASCADE)
invited_to = models.ForeignKey(Company, on_delete=models.CASCADE)
talk = models.ManyToManyField(Talk)
def __str__(self):
return self.speaker.name + ' by ' + self.invited_to.name
class Speaker(models.Model):
name = models.CharField(max_length=200, blank=False, null=True)
company = models.ForeignKey(Company, on_delete=models.CASCADE)
talk = models.ManyToManyField(Talk)
所以在我看來,我送invites = Invitation.objects.all()
和我需要在我的模板是訪問配置文件的名稱:Invitation.invited_to。 Company.Profile.name以及Invitation.speaker.Company.Profile.name。
有沒有什麼方法可以做到這一點?