3
我需要的是下面给出的formset中每个表单的单选按钮。django嵌入式formset的单选按钮
class AppvideoDemoForm(forms.ModelForm):
class Meta:
model = AppvideoDemo
def __init__ (self, *args, **kwargs):
super(AppvideoDemoForm, self).__init__(*args, **kwargs)
self.fields['active'] = forms.BooleanField(widget = forms.RadioSelect(choices=((self.prefix, 'Set this as primary'),)))
def add_prefix(self, field):
if field == 'active':
return field
else:
return self.prefix and ('%s-%s' % (self.prefix, field)) or field
AppvideoDemoFormSet = inlineformset_factory(Applications, AppvideoDemo, extra=3,form=AppvideoDemoForm,formset=MandatoryInlineFormSet, can_delete=False)
但是,当我尝试自己的方式时发现单选按钮是不可选择和多选的。
我想你是不是清楚我的问题。我有一个形式为AppVideoDemoForm的inlineformset,它具有一个布尔型字段'active'。需要将formset中的任意一个表单设置为活动状态。 – anoop 2014-09-10 12:55:59