I'm looking for an elegant way of stepping through my models from
within my template tags.

I have 3 model classes chained by many-to-many relationships, viz
Category --> Item --> Detail.  This model pertains to resume data,
e.g., Category='Education', Item='Univ1', Detail='Biology
coursework'.  Each model class has various subfields which I would
like to display on the final resume page.

I have tried various approaches involving {% for %} loops, and each
has resulted in failure.  Each of my attempts requires using a
variable name as a model's attribute lookup.  Unfortunately, it seem
the Django templating language attempts to access the variable's name,
not its value.

Approach 1):

I have pulled the field names from metadata in the view:

fields = []
for f in Item._meta.fields:
    fields.append(f.column)

{% for c in categories %}
  {% for i in c.items.all %}
    {% for f in fields %}
      {{ i.f }}
    {% endfor %}
  {% endfor %}
{% endfor %}

There's no resulting output, indicating Django was looking for an "f"
attribute to the Item instance contained in "i".

I was thinking about using a {% with %} block to concatenate the value
of "f" to the end of the "i" Item instance.  It just seems incredibly
inelegant to have to explicitly list every field name I want
displayed.

Regards.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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