Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ModelMultipleChoiceField as a multi-column table

Tags:

forms

django

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>.

like image 573
Deniz Dogan Avatar asked Apr 30 '09 20:04

Deniz Dogan


1 Answers

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.

like image 100
Grant Avatar answered Oct 12 '22 23:10

Grant