开发者

Accessing Django OneToOneField in templates?

开发者 https://www.devze.com 2023-03-20 09:46 出处:网络
I have the following scenario. class A(models.Model): a = models.IntegerField() class B(models.Model): c = models.OneToOneField(A)

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?

Than开发者_如何学JAVAks.


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

{{ a.b.d }}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号