I'm using Django 1.0.2, with plans to upgrade to 1.2.5 at some point.
I have an application that basically just displays the results of a
database lookup as a table. In a fit of DRY-ism, I decided it would
be cool if my application inspected the model to figure out what
columns to display; that way my template doesn't have to duplicate
what's in the model (and duplicate it in several places, which I
dislike for obvious reasons).
So I created col_list, which is passed to the template and contains
column information. One important field is col_list.name, which is
simply name of the model field in question.
Here's what I want to do:
<table>
<tr>
{% for col in col_list %}
...generate header for column...
{% endfor %}
</tr>
{% for row in database_query %}
<tr>
{% for col in col_list %}
<td>
{{ row.{{col.col_name}} }} <!-- OOPS -->
</td>
{% endfor %}
</tr>
{% endfor %}
</table>
The header part works just fine. But the "OOPS" part doesn't work,
because you can't use the result of a variable lookup as input to
another lookup. I looked at the parsing code and the lookup code, and
achieving the effect I want seems a bit tricky, even if I were to
write a new template tags.
Am I up a creek? Or is there some trick I'm missing here?
--
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.