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 %}
精彩评论