Nullpoet
Nullpoet

Reputation: 11269

With django forms how to organize fields in multiple columns?

class MyForm(forms.Form):
  row_1 = forms.ChoiceField(widget=forms.RadioSelect, choices=CHOICES)
  row_2_col_1 = forms.ChoiceField(widget=forms.RadioSelect, choices=CHOICES)
  row_2_col_2 = forms.ChoiceField(widget=forms.RadioSelect, choices=CHOICES)

  def render_form(request):
    form = MyForm()
    # render form

What should be my template so that final html is something like

<table>
<tr> row_1 field.. </tr>
<tr>
  <td> row_2_col_1 field.. </td>
  <td> row_2_col_2 field.. </td>
</tr>

Upvotes: 0

Views: 1437

Answers (1)

deadly
deadly

Reputation: 1192

If you've passed the table to the form in the request you just need to use Django template mark up:

<table>
<tr>{{ table.row_1 }}</tr>
<tr>
  <td>{{ table.row_2_col_1 }}</td>
  <td>{{ table.row_2_col_2 }}</td>
</tr>

Upvotes: 1

Related Questions