On Fri, Sep 16, 2011 at 10:57 AM, David <[email protected]> wrote:
> I had imagined therefore I would be able to iterate through the
> Person's that belong to the Company using the following syntax:
>
> {% for p in person %}
> {{ p.first_name }}
> {% endfor %}
>
> But I'm told that the company object is not iterable. Neither can I
> just do company.first_name to get a person's name.
the template syntax should be something like this:
{% for p in company.person_set.all %}
{{ p.first_name }}
{% endfor %}
note that in the 'GET' case, you're not initializing the 'a' variable.
besides fixing that, you don't need any change in the view. the
select_related() call i mentioned can reduce the numbe of SQL queries,
but in this case it's just a single extra query, so first make it
work, then worry about optimizations.
--
Javier
--
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.