Ticket #8760: 8760.diff

File 8760.diff, 2.8 KB (added by Tim Graham, 9 years ago)
  • django/forms/models.py

    diff --git a/django/forms/models.py b/django/forms/models.py
    index c5d1423..798df93 100644
    a b class ModelMultipleChoiceField(ModelChoiceField):  
    12171217    widget = SelectMultiple
    12181218    hidden_widget = MultipleHiddenInput
    12191219    default_error_messages = {
    1220         'list': _('Enter a list of values.'),
     1220        'invalid_list': _('Enter a list of values.'),
    12211221        'invalid_choice': _('Select a valid choice. %(value)s is not one of the'
    12221222                            ' available choices.'),
    12231223        'invalid_pk_value': _('"%(pk)s" is not a valid value for a primary key.')
    class ModelMultipleChoiceField(ModelChoiceField):  
    12391239        elif not self.required and not value:
    12401240            return self.queryset.none()
    12411241        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')
    12431243        qs = self._check_values(value)
    12441244        # Since this overrides the inherited ModelChoiceField.clean
    12451245        # we run custom validators here
    class ModelMultipleChoiceField(ModelChoiceField):  
    12601260        except TypeError:
    12611261            # list of lists isn't hashable, for example
    12621262            raise ValidationError(
    1263                 self.error_messages['list'],
    1264                 code='list',
     1263                self.error_messages['invalid_list'],
     1264                code='invalid_list',
    12651265            )
    12661266        for pk in value:
    12671267            try:
  • docs/ref/forms/fields.txt

    diff --git a/docs/ref/forms/fields.txt b/docs/ref/forms/fields.txt
    index c53d4f2..8e36459 100644
    a b method::  
    11751175    * Normalizes to: A ``QuerySet`` of model instances.
    11761176    * Validates that every id in the given list of values exists in the
    11771177      queryset.
    1178     * Error message keys: ``required``, ``list``, ``invalid_choice``,
     1178    * Error message keys: ``required``, ``invalid_list``, ``invalid_choice``,
    11791179      ``invalid_pk_value``
    11801180
    11811181    The ``invalid_choice`` message may contain ``%(value)s`` and the
  • tests/forms_tests/tests/test_error_messages.py

    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):  
    256256        e = {
    257257            'required': 'REQUIRED',
    258258            'invalid_choice': '%(value)s IS INVALID CHOICE',
    259             'list': 'NOT A LIST OF VALUES',
     259            'invalid_list': 'NOT A LIST OF VALUES',
    260260        }
    261261        f = ModelMultipleChoiceField(queryset=ChoiceModel.objects.all(), error_messages=e)
    262262        self.assertFormErrors(['REQUIRED'], f.clean, '')
Back to Top