我有一个三层“深度”模型,我想通过我的模板访问它:
楷模:
class Match(models.Model):
pl1 = models.IntegerField(default=0)
pl2 = models.IntegerField(default=0)
boards = models.ManyToManyField(Scoreboard)
active = models.IntegerField(default=1)
turn = models.IntegerField(default=0)
def __unicode__(self):
return "Match " + str(self.id)
class Scoreboard(models.Model):
user = models.ForeignKey(User)
我只是在猜测,但要获得连接到每个“匹配”的用户名称,不应该是这样的:
{% for active in matches %}
{{active}} - {{active.boards.user}}<br>
{% endfor %}