﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
16306	Form field documentation documents optional keyword arguments as  field attributes.	ShawnMilo	Abhishek Mane	"I've tested this for forms.IntegerField and forms.DecimalField -- setting a max_value when the field is declared works normally, but if set in __init__ (because it's unknown till runtime) no validators are assigned although the max_value value is properly set.

{{{

from django import forms

class TestForm(forms.Form):
    amount = forms.IntegerField(max_value = 10)

class TestForm2(forms.Form):
    amount = forms.IntegerField()

    def __init__(self, *args, **kwargs):
        super(TestForm2, self).__init__(*args, **kwargs)
        self.fields['amount'].max_value = 10

x = TestForm({'amount': 12})
print x.is_valid() #returns False
print x.fields['amount'].max_value # returns 10
print x.fields['amount'].validators # [<django.core.validators.MaxValueValidator object at 0x7febd5240610>]
print x.errors #complains about size


x = TestForm2({'amount': 12})
print x.is_valid() #returns True
print x.fields['amount'].max_value #returns 10
print x.fields['amount'].validators # []
print x.errors #nothing


}}}

Evidently this bug has existed for some time, because almost a year ago it was discussed on StackOverflow and the suggestion was to just completely replace the field at runtime:

http://stackoverflow.com/questions/3470741/django-forms-integerfield-set-max-value-on-runtime
"	Bug	assigned	Forms	dev	Normal		form field documentation	bmispelon@…	Accepted	0	0	0	0	0	0
