tags:

views:

282

answers:

1

In Django, how do I render a ModelMultipleChoiceField as a multi-column <table>?

fav = forms.ModelMultipleChoiceField(Show.objects.all(),
                                     widget=forms.CheckboxSelectMultiple)

I want this field to render as a multi-column table. Which is the best way to do that?

To clarify, I want the rendering to take N objects and render an HTML <table> with one checkbox in each cell, across e.g. three columns in each <tr>.

+3  A: 

Django is hard-coded to use a <ul> here. See the widgets.py code.

You could subclass the CheckboxSelectMultiple widget class and provide your own .render() method using tables.

Grant
See http://skyl.org/log/post/skyl/2010/01/subclass-django-forms-widgets-radiofieldrenderer-and-django-forms-widgets-radioselect-for-custom-rendering-of-individual-choices/ for a code snippet doing something very similar.
pfctdayelise