I've got a form like this:
class SomeForm(forms.Form):
first = forms.IntegerField(max_value= DontWantToSetYet)
second = forms.IntegerField(max_value= DontWantToSetYet)
third = forms.IntegerField(max_value= DontWantToSetYet)
How can I set the max_values at runtime? I.E
if request.method == 'POST':
form = SomeForm(request.POST, max_values = {'first':10,'second':50,'third':666})
[...]
After reading django source, I came up with something like this:
The checking part is because it would sometimes add the same validator several times (No idea why)
[edit] After checking again, this isn't working as it should. Apparently it always uses the max_values of the first person to use the form - it doesn't make much sense really.
you can set the max values on fields in the
__init__
method, as shown hereedit:
didn't worked when I tried, redefining the field definition like this works