Hi,

Just want to know if this is the correct understanding of how model
instances are passed to templates.

If I load a model instance object into a template - is it the case
that I also implicitly load in any instance objects it is related
through foreign key fields? It seems that these, and in turn, any
foreign keys those objects have, are also loaded.

eg
    return render_to_response("startpage.html", {
        'A': instance1,
    }, context_instance=RequestContext(request))

so in the template I can do things like:

{{ A.fk_field.name }}
{{ A.fk_field.another_fk_field.name}}

Is this correct - and how should it be controlled - supposing I really
do only want 'instance1' without FK following.

Is it also the case if I want access to an instance's reverse
relationship objects I have to explicitly load those into the template
seperately?
eg
    return render_to_response("startpage.html", {
        'A': instance1,
        'BList': instance1.other_set.all(),
    }, context_instance=RequestContext(request))

so in the template I can do

{% for B in BList %}
do something with B
{% endfor %}

Sorry if this is answered elsewhere but just couldn't find it!

Thanks
                     Alex

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to