I have two models, named as Human and Animal. The primary key of Human is foreign key in the Animal model. Both has 3 columns each. Human model has c, e, r columns. Animal model has l, i, p columns. I am running a django query on Human model, like this.
result = Human.objects.filter().order_by('r')
result is an queryset object. This object is sent from my view file to a django template page. Inside template page I am looping through result and displaying the column values.
Now what i want to do is, I want to also fetch value of p column(which is present in the Animal model) inside the same loop, inside that django template. How can we do it in the django template page.
In the python file I can do like this
for i in result:
print i.animal_set.values()[0]['p']
But I want to do it in the template page.
1 Answer