The World’s Largest Online Community for Developers
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