diff --git a/django/core/exceptions.py b/django/core/exceptions.py
index c92e8d4..ead960f 100644
a
|
b
|
class ValidationError(Exception):
|
113 | 113 | if not isinstance(messages, ValidationError): |
114 | 114 | messages = ValidationError(messages) |
115 | 115 | self.error_dict[field] = messages.error_list |
| 116 | self.code = code |
116 | 117 | |
117 | 118 | elif isinstance(message, list): |
118 | 119 | self.error_list = [] |
diff --git a/tests/test_exceptions/test_validation_error.py b/tests/test_exceptions/test_validation_error.py
index a0bbfaf..65cb150 100644
a
|
b
|
class TestValidationError(unittest.TestCase):
|
14 | 14 | message_dict['field2'] = ['E3', 'E4'] |
15 | 15 | exception = ValidationError(message_dict) |
16 | 16 | self.assertEqual(sorted(exception.messages), ['E1', 'E2', 'E3', 'E4']) |
| 17 | |
| 18 | def test_dict_and_code(self): |
| 19 | message_dict = { |
| 20 | 'field1': ['E1', 'E2'], |
| 21 | 'field2': ['E3', 'E4'], |
| 22 | } |
| 23 | exception = ValidationError(message_dict, code='foo') |
| 24 | self.assertEqual(exception.code, 'foo') |