我是django的新手.
我想创建一个自定义小部件.
forms.py:
from project.widgets import MultiChoiceFilterWidget
class CustomSearchForm(FacetedSearchForm):
TEST_COLORS = [
u"Blau", u"Rot", u"Gelb"
]
color = forms.MultipleChoiceField(
label=_("Color"), choices=[(x, x) for x in TEST_COLORS],
widget=MultiChoiceFilterWidget, required=False)
Run Code Online (Sandbox Code Playgroud)
widget.py:
class MultiChoiceFilterWidget(forms.widgets.CheckboxSelectMultiple):
template_name = 'project/widgets/filter.html'
option_template_name = 'ptoject/widgets/filter_option.html'
Run Code Online (Sandbox Code Playgroud)
项目/部件/ filter.html:
<h1>TEST</h1>
Run Code Online (Sandbox Code Playgroud)
但它不会渲染新模板,相反它仍然呈现旧方式.
你能给我一些提示吗?
我有一个带有双选单选按钮元素的Django表单.我希望表单呈现或多或少像这样:
( ) I prefer beer
The last sporting event I attended was: [ ]
My favorite NASCAR driver is: [ ]
( ) I prefer wine
The last opera/play I attended was: [ ]
My favorite author is: [ ]
换句话说,我想分开两个单选按钮选项.我怎么做?使用默认的form.as_table渲染,选项彼此相邻,我不想要.
(向NASCAR和歌剧爱好者道歉.)