Radio button for django embedded formset

I need a radio button for each form in the below set of forms.

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)

      

But the switches were not selectable and multipurpose when I tried in my own way.

+3


source to share


1 answer


to present radio buttons, you need to use the checkboxfield whites radiooselect widgets.

choices = (('0', 'LORENZO_LAMAS'), (1, 'EL RENEGADO'))
filters = forms.ChoiceField(required=True,
                            widget=forms.RadioSelect(attrs={'class': ''}),
                            choices=choices)

      



I hope this solves your problem.

0


source







All Articles