Take the 2-minute tour ×

Is there any way, to change the field's *min_length* argument inside form constructor? That doesn't work:

    super(CreateTeamForm, self).__init__(*args, **kwargs)
    self.fields['primary_color'].min_length = 4
share|improve this question

1 Answer 1

up vote 4 down vote accepted

Try setting the field's validators attribute in the __init__ method.

from django.core.validators import MinLengthValidator

class MyForm(forms.Form):
    primary_color = forms.CharField()
        # get all the validators on the field which are not MinLengthValidator
        validators = [v for v in self.fields['primary_color'].validators if not isinstance(v, MinLengthValidator)]
        min_length = 10
        self.fields['primary_color'].validators = validators
share|improve this answer

Your Answer


