I have set of models, with relationships D -> C -> B -> A, where the
"->" indicates a "many to one" relationship.
I have been able to create a filtered queryset on child model D, based
on a value in a parent model A, using the following syntax:
my_query = D.objects.filter(C__B__A__name__icontains = "foo")
where model A has a field called "name".
I need to be able to display the value of the "name" field from A,
along with the field attribute data from D in a template.
I have therefore added the following to the end of my_query:
.select_related('C__B__A__name')
Assuming the template is called with the context containing:
'results': my_query
then I can use {{ results.name }}, for example, to retrieve the value
of the "name" field from model D.
However I am unable to figure out the correct syntax for retrieving
the value of the "name" field from related model A.
I have tried {{ results.C.B.A.name }} with no effect?
What is the correct way to do this?
Thanks
Derek
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.