Django does not respect the max_length attribute of TextField model field while validating a ModelForm.
So I define a LimitedTextField inherited from the models.TextField and added validation bits similar to models.CharField:
from django.core import validators class LimitedTextField(models.TextField): def __init__(self, *args, **kwargs): super(LimitedTextField, self).__init__(*args, **kwargs) self.max_length = kwargs.get('max_length') if self.max_length: self.validators.append(validators.MaxLengthValidator(self.max_length)) def formfield(self, **kwargs): defaults = {'max_length': self.max_length} defaults.update(kwargs) return super(LimitedTextField, self).formfield(**defaults) But this still has no affect on ModelForm validation.
What am I missing?