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?
Just to fill in a bit more of Béres Botond's answer
The custom renderer would look like:
In this case I didn't want the name of the radio box next to it, so I am using "force_unicode(w.tag())" If you wanted the name next to it, just render the object directly like "force_unicode(w)"
I hope that helps!
If you need to customize the input elements further, overwrite the choice_input_class attribute on the custom renderer.
These
render()
andtag()
methods are from the 1.9 source code, modified only slightly to show the application of a simple customization in each.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
You could also use django-uni-form and use divs instead of tables.