The World’s Largest Online Community for Developers

'; Django use a widget as a radio selection option - LavOzs.Com

I would like to have a radio choice of a list of integer values in a Django form, however in the last option would be an integer field whereby the user can select their own value.

Is this possible using a class based Form, or would it be easier to modify the template?

At the moment I have passed the kwargs to the form ready to output, but am having trouble creating the integer selection as an option. At the moment I have:

radio_choice = forms.IntegerField(initial=1, min_value=1)
test = None

def __init__(self, *args, **kwargs):
    super(InitForm, self).__init__(*args, **kwargs)
    self.fields['test'] = forms.CharField(label='Test', widget=forms.RadioSelect(choices=[(1,1),(2, 2),(3, self.fields['radio_choice'])]))

but am getting on the page:

<django.forms.fields.IntegerField object at 0x109e8b2b0>

instead of the object

differentiate null=True, blank=True in django
django - Creating a radio select with select box options
Django modelformset order_by not working
Initial value is not working for ChoiceField on django-filters
Django - use Radio Buttons instead of Select for form component
django form field throws error when blank and null are set
Queryset for django-select2 widget being ignored
Django model-forms widget choice based on URL variables