我在我的项目中使用django-mptt。表格是:
class UserSettingsForm(forms.ModelForm):
category = TreeNodeMultipleChoiceField(
required=True,
queryset=NewsCategory.objects.all(), label=u"category", widget=forms.CheckboxSelectMultiple()
)
class Meta:
model = UserSettings
我想在父母选中时选择孩子。我怎样才能做到这一点? 提前致谢
答案 0 :(得分:1)
您需要向表单或窗口小部件添加自定义JS代码。就像Form Media
中的文档一样对于小部件(自定义):
class CalendarWidget(forms.TextInput):
class Media:
css = {
'all': ('pretty.css',)
}
js = ('animations.js', 'actions.js')
或整个表格:
class ContactForm(forms.Form):
date = DateField(widget=CalendarWidget)
name = CharField(max_length=40, widget=OtherWidget)
class Media:
css = {
'all': ('layout.css',)
}