Display additional data while iterating over a Django formset

Posted by Jannis on Stack Overflow See other posts from Stack Overflow or by Jannis
Published on 2010-06-06T17:43:20Z Indexed on 2010/06/06 17:52 UTC
Read the original article Hit count: 340

Filed under:
|
|

Hi,

I have a list of soccer matches for which I'd like to display forms. The list comes from a remote source.

matches = ["A vs. B", "C vs. D", "E vs, F"]
matchFormset = formset_factory(MatchForm,extra=len(matches))
formset = MatchFormset()

On the template side, I would like to display the formset with the according title (i.e. "A vs. B").

{% for form in formset.forms %}
    <fieldset>
        <legend>{{TITLE}}</legend>
        {{form.team1}} : {{form.team2}}
    </fieldset>
{% endfor %}

Now how do I get TITLE to contain the right title for the current form? Or asked in a different way: how do I iterate over matches with the same index as the iteration over formset.forms?

Thanks for your input!

© Stack Overflow or respective owner

Related posts about python

Related posts about django