On 8/25/2010 10:00 PM, Yo-Yo Ma wrote:
> I'm wanting to build out a list template that can display any list of
> objects in this manor (pseudo code:
> 
> {% for thing in things %}
> <tr>
>     <td>{{ thing.foo }}</td>
>     <td>{{ thing.bar }}</td>
>     <td>{{ thing.spam }}</td>
>     <td>{{ thing.eggs }}</td>
> </tr>
> {% endfor %}
> 
> The problem is, of course, that I want to list more than just "things"
> using the same template. Things have "foo", "bar", "spam", and "eggs".
> "Widgets" might only have "snafu", and "peanut_butter" attributes.
> 
> Thanks
> 
As usual, this kind of logic doesn't belong in the template.

You should do all the introspection in the view, and then have your
template display the stuff that the display passes through. This you
will have one loop over the objects (rows), and then an inner loop to
display the individual fields (columns).

Don't forget that if you want to insert table headers your logic will
need to account for a variable number of those too.

regards
 Steve
-- 
DjangoCon US 2010 September 7-9 http://djangocon.us/

-- 
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.

Reply via email to