假设我有模特:
class model1(model.Models):
name = CharField(max_length = 20)
phone = IntegerField(max_length = 20)
class model2(model.Models):
name = ForeignKeyFeild(model1)
team = CharField(max_length = 20)
如果我在视图中设置了这样的modelformset工厂:
qset = model2.objects.all()
fset = modelformset_factory(model2, fields = ('team', 'name')
form = fset(queryset = qset)
在模板中,如何显示' phone'的价值?来自model1?
当我在模板中渲染表单时:
{% for f in form %}
{{f.team.value}} # this gives me the value without an input field
{{f.name.phone}} # this however renders nothing and that's what I'm trying to find out
{%endfor%}
如何将{{f.name.phone}}作为其持有foreign_key节目的表中的信息?