I want to render the django form widget radioselect into a table rather than a ul list. With labels in the first row and the radio buttons below in the second row. One cell for each button. e.g.
-------------------------------
| label 1 | label 2 | label 3 |
-------------------------------
| O | O | O |
-------------------------------
I've looked at the default selectradio widget but the render function seems so complicated, calling many different classes to do each part of the render.
Does anyone have any examples of how to do this or could provide a simple solution?
You need to subclass django.forms.widgets.RadioFieldRenderer and override it's render method. Then in your form, when declaring your field specify the custom renderer for the widget
class MyForm(forms.ModelForm):
my_field = forms.TypedChoiceField(choices=some_choices,
label=u"bla",
widget=forms.RadioSelect(renderer=MyCustomRenderer))