我想在我的模板中顯示答案主題和問題。我如何從我的模板中的Answer類中調用這些變量?Django:我如何在模型中向模板顯示此變量信息
這裏是我的課怎麼看起來
Model.py:
class Answer(models.Model):
subject = models.ForeignKey(Subject, help_text = u'The user who supplied this answer')
question = models.ForeignKey(Question, help_text = u"The question that this is an answer to")
runid = models.CharField(u'RunID', help_text = u"The RunID (ie. year)", max_length=32)
answer = models.TextField()
def __unicode__(self):
return "Answer(%s: %s, %s)" % (self.question.number, self.subject.surname, self.subject.givenname)
def choice_str(self, secondary = False):
choice_string = ""
choices = self.question.get_choices()
for choice in choices:
for split_answer in self.split_answer():
if str(split_answer) == choice.value:
choice_string += str(choice.text) + " "
模板:
{{ subject }}
{{ question }}
{{ answer }}?????
我是相當新的Django和我的學習我只有幾個星期。