Django:从模板访问ForeignKey值的最佳方法

时间:2013-10-13 09:08:30

标签: django templates django-models django-templates django-views

卡片模型有许多锻炼模型(ForeignKey to Card),每个锻炼模型都有许多锻炼名称模型(ForeignKey to Workout)。我想在模板中访问Exercise Name值。哪种方式最好?

1 个答案:

答案 0 :(得分:1)

首先请编辑你的问题,使用正确的“ForeignKey X”,很难说出你的FK是什么。

但是要回答你的问题,foo_idfoo FK字段的整数表示。

也就是说,print record.exercise会在练习模型上调用__unicode__()来获取要打印的代表,print record.exercise_id将打印实际的FK ID。