> Folks,
> 
> I would appreciate some help figuring out how to create a
> templated form scenario.  The quick form of the question is
> either:
> 
>     How do I iterate over two form field list simultaneously
>     in my template using {% for f in form %}, sort of like
>     {% for f,g in form1,form2 %}?
> or    
>     How do I iterate over a list of strings and use that to
>     select form fields in my template?
> 
> 
> Gory details of and failed attempts follow...

So, for the record, I failed to get any form of proper
template variable use or lookup to do what I needed.

However, I was able to achieve success in my table construction
using the following custom template filter as found here:

    
http://diffract.me/2009/09/django-template-filter-show-list-of-objects-as-table-with-fixed-number-of-columns/

---- File: my_filter.py --------------------------------------------

    from django import template

    register = template.Library()

    def tablecols(data, cols):
        rows = []
        row = []
        index = 0
        for user in data:
            row.append(user)
            index = index + 1
            if index % cols == 0:
                rows.append(row)
                row = []
        # Still stuff missing?
        if len(row) > 0:
            rows.append(row)
        return rows

    register.filter('tablecols', tablecols)

and then in my template:

    {% load my_filters %}

and:

    {% for row in attr_form|tablecols:2 %}
        <tr>
        {% for f in row %}
            {% if forloop.first %}
                <td>{{ f.label }}</td>
            {% endif %}
            <td>{{f.errors}}{{f}}</td>
        {% endfor %}
        </tr>
    {% endfor %}


HTH,
jdl

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