diff --git a/django/forms/models.py b/django/forms/models.py
index c5d1423..798df93 100644
a
|
b
|
class ModelMultipleChoiceField(ModelChoiceField):
|
1217 | 1217 | widget = SelectMultiple |
1218 | 1218 | hidden_widget = MultipleHiddenInput |
1219 | 1219 | default_error_messages = { |
1220 | | 'list': _('Enter a list of values.'), |
| 1220 | 'invalid_list': _('Enter a list of values.'), |
1221 | 1221 | 'invalid_choice': _('Select a valid choice. %(value)s is not one of the' |
1222 | 1222 | ' available choices.'), |
1223 | 1223 | 'invalid_pk_value': _('"%(pk)s" is not a valid value for a primary key.') |
… |
… |
class ModelMultipleChoiceField(ModelChoiceField):
|
1239 | 1239 | elif not self.required and not value: |
1240 | 1240 | return self.queryset.none() |
1241 | 1241 | if not isinstance(value, (list, tuple)): |
1242 | | raise ValidationError(self.error_messages['list'], code='list') |
| 1242 | raise ValidationError(self.error_messages['invalid_list'], code='invalid_list') |
1243 | 1243 | qs = self._check_values(value) |
1244 | 1244 | # Since this overrides the inherited ModelChoiceField.clean |
1245 | 1245 | # we run custom validators here |
… |
… |
class ModelMultipleChoiceField(ModelChoiceField):
|
1260 | 1260 | except TypeError: |
1261 | 1261 | # list of lists isn't hashable, for example |
1262 | 1262 | raise ValidationError( |
1263 | | self.error_messages['list'], |
1264 | | code='list', |
| 1263 | self.error_messages['invalid_list'], |
| 1264 | code='invalid_list', |
1265 | 1265 | ) |
1266 | 1266 | for pk in value: |
1267 | 1267 | try: |
diff --git a/docs/ref/forms/fields.txt b/docs/ref/forms/fields.txt
index c53d4f2..8e36459 100644
a
|
b
|
method::
|
1175 | 1175 | * Normalizes to: A ``QuerySet`` of model instances. |
1176 | 1176 | * Validates that every id in the given list of values exists in the |
1177 | 1177 | queryset. |
1178 | | * Error message keys: ``required``, ``list``, ``invalid_choice``, |
| 1178 | * Error message keys: ``required``, ``invalid_list``, ``invalid_choice``, |
1179 | 1179 | ``invalid_pk_value`` |
1180 | 1180 | |
1181 | 1181 | The ``invalid_choice`` message may contain ``%(value)s`` and the |
diff --git a/tests/forms_tests/tests/test_error_messages.py b/tests/forms_tests/tests/test_error_messages.py
index d2a8005..cb3f4ae 100644
a
|
b
|
class ModelChoiceFieldErrorMessagesTestCase(TestCase, AssertFormErrorsMixin):
|
256 | 256 | e = { |
257 | 257 | 'required': 'REQUIRED', |
258 | 258 | 'invalid_choice': '%(value)s IS INVALID CHOICE', |
259 | | 'list': 'NOT A LIST OF VALUES', |
| 259 | 'invalid_list': 'NOT A LIST OF VALUES', |
260 | 260 | } |
261 | 261 | f = ModelMultipleChoiceField(queryset=ChoiceModel.objects.all(), error_messages=e) |
262 | 262 | self.assertFormErrors(['REQUIRED'], f.clean, '') |