Accessing Django OneToOneField in templates?

假装没事ソ 提交于 2019-12-18 18:51:18

问题


I have the following scenario.

class A(models.Model):
    a = models.IntegerField()

class B(models.Model):
    c = models.OneToOneField(A)
    d = models.DecimalField()

In my templates, I have a list of objects A. In my template how do I access the attribute "d" from my template?

Thanks.


回答1:


class B(models.Model):
    c = models.OneToOneField(A, related_name='b')
    d = models.DecimalField()

{{ a.b.d }}


来源:https://stackoverflow.com/questions/6676134/accessing-django-onetoonefield-in-templates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!