diff --git a/django/contrib/localflavor/uk/forms.py b/django/contrib/localflavor/uk/forms.py index 7df736444aa..aafe9734db5 100644 --- a/django/contrib/localflavor/uk/forms.py +++ b/django/contrib/localflavor/uk/forms.py @@ -33,7 +33,7 @@ class UKPostcodeField(CharField): # Put a single space before the incode (second part). postcode = self.space_regex.sub(r' \1', postcode) if not self.postcode_regex.search(postcode): - raise ValidationError(self.default_error_messages['invalid']) + raise ValidationError(self.error_messages['invalid']) return postcode class UKCountySelect(Select): diff --git a/tests/regressiontests/forms/localflavor/uk.py b/tests/regressiontests/forms/localflavor/uk.py index 258c22e5a95..cd6c8edf849 100644 --- a/tests/regressiontests/forms/localflavor/uk.py +++ b/tests/regressiontests/forms/localflavor/uk.py @@ -58,4 +58,15 @@ u'BT32 4PX' u'' >>> f.clean('') u'' +>>> class MyUKPostcodeField(UKPostcodeField): +... default_error_messages = { +... 'invalid': 'Enter a bloody postcode!', +... } +... +>>> +>>> f = MyUKPostcodeField(required=False) +>>> f.clean('1NV 4L1D') +Traceback (most recent call last): +... +ValidationError: [u'Enter a bloody postcode!'] """