Hi, in my Django application I've got a form with a ChoiceField that normally allows to choice between a range of integer values.
class FormNumber(forms.Form):
list=[]
for i in range(1, 11):
list.append((i,i))
number=forms.ChoiceField(choices=list, initial=1)
Now I need to override the default choices list from a view method in some cases, using a smaller range, but trying to do it in this way
n=10-len(request.session["items"])
if n>0:
list=[]
for i in range(1, n+1):
list.append((i,i))
form=FormNumber(choices={'number':list}, initial={'number':1})
I get a TypeError - __ init__() got an unexpected keyword argument 'choices'. I tried also to remove the parameters from the form class, but I get the same result.
Is there a way to initialize the ChoiceField with a new choices list from the view in a way similar to the one above? Thanks in advance :)