You can also do the following. in your def class class:
max_number = forms.ChoiceField(widget = forms.Select(), choices = ([('1','1'), ('2','2'),('3','3'), ]), initial='3', required = True,)
then when you call the form in your view, you can dynamically set both the initial options and the selection list.
yourFormInstance = YourFormClass() yourFormInstance.fields['max_number'].choices = [(1,1),(2,2),(3,3)] yourFormInstance.fields['max_number'].initial = [1]
Note: the initial values ββshould be a list, and the selection should be 2-tuples, in my example above I have a list of 2 tuples. Hope this helps.
Burton Williams Jul 01 2018-10-01T00: 14
source share