开发者

ForeignKey, show values in template

I have two classes:

开发者_Go百科class People
    name = CharField()

class Equipment
    name = Charfield()
    responsible = ForeignKey(People)

and view:

def persone_detail(request, tab_number):
    return direct_to_template(request, 'person.html', {
       'persone': Peoples.objects.filter(tab_number=tab_number)

How can I show in template the name from equipment?


By following the reverse relationship to Equipment: http://docs.djangoproject.com/en/dev/topics/db/queries/#following-relationships-backward

{% for person in persone %}
    Person: {{ person.name }}
    {% for equipment in person.equipment_set.all %}
        Equipment: {{ equipment.name }}
    {% endfor %}
{% endfor %}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜