ModelMultipleChoiceField作为多列表 [英] ModelMultipleChoiceField as a multi-column table

查看:109
本文介绍了ModelMultipleChoiceField作为多列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Django中,如何将ModelMultipleChoiceField渲染为多列< table>

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?

为了澄清,我希望渲染采取N个对象并呈现一个HTML < table> 每个单元格中的一个复选框,跨越例如每个< tr> 中的三列。

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

推荐答案

Django很难编码为在这里使用< ul> 。请参阅 widgets.py 代码。

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

您可以将 CheckboxSelectMultiple 小部件类子类化,并提供您自己的 .render() code>方法使用表。

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

这篇关于ModelMultipleChoiceField作为多列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆