5

Following the code in this post, I was able to group the options in a ModelMultipleChoiceField based on another field. As described in this post, I used a custom widget (literally the one that is in the post):

Grouping CheckboxSelectMultiple Options in Django

so now the form is rendering the way I'd like it to, but I was hoping to improve on the formatting by using crispy forms. however, when I added {% load crispy_forms_tags %} and {{form|crispy}} it rendered the form without the grouping that I worked so hard to achieve...

does anyone know how if its possible to apply crispy forms to a form with a custom widget and preserve what the widget does?

thanks!

4

1 回答 1

7

不,这是不可能的,因为脆皮表单从不调用render小部件的方法。

另一种方法是覆盖小部件的模板,在这种情况下bootstrap/layout/checkboxselectmultiple.html,根据需要使用分组。

https://github.com/maraujop/django-crispy-forms/blob/dev/crispy_forms/templates/bootstrap/layout/checkboxselectmultiple.html

于 2013-09-05T07:51:55.730 回答