def to_python(self, value): if len(str(value)) != 2 or not str(value).isalpha(): raise ValidationError("State must be a valid two-character code.") return str(value).upper()