On May 25, 1:46 pm, vishy <[email protected]> wrote:
> Hi,
> My requirement is to display a 2-column table (moves to be entered by
> user for white and black of a chess game) with 10 rows for input
> (textbox).How can I use forms module to achieve this? Is it possible?
> thanks
I think the easiest way to do this would be to use a formset [1] and a
custom template. Something according the following lines
class ChessMoveForm(forms.Form):
white = forms.CharField(label='white moves')
black = forms.CharField(label='black moves')
ChessMoveFormSet = forms.formsets.formset_factory(ChessMoveForm,
extra=10)
then pass an initialised instance of formset=ChessMoveFormSet() to
your template, where you can write
<form action="" method="post">
{{ formset.management_form }}
<table>
{% for form in formset.forms %}
{% if forloop.first %}
<tr>
{% for field in form %}
{% if not field.is_hidden %}
<th>{{ field.label }}</th>
{% endif %}
{% endfor %}
</tr>
{% endif %}
<tr>
{% for field in form %}
<td>{{ field }}{{ field.errors }}</td>
{% endfor %}
</tr>
{% endfor %}
<tr><td><input type="submit" /></td><td><input type="reset" /></td></
tr>
</table>
</form>
to present your form.
[1]: http://docs.djangoproject.com/en/dev/topics/forms/formsets/
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---