Changes between Initial Version and Version 1 of Ticket #32347


Ignore:
Timestamp:
Jan 12, 2021, 10:28:56 PM (4 years ago)
Author:
Aaron Wiegel
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #32347 – Description

    initial v1  
    11Compared with `ChoiceField` and others, `ModelChoiceField` does not show the value of the invalid choice when raising a validation error. Passing in parameters with the invalid value and modifying the default error message for the code `invalid_choice` should fix this.
     2
     3From source code:
     4
     5
     6{{{
     7class ModelMultipleChoiceField(ModelChoiceField):
     8    """A MultipleChoiceField whose choices are a model QuerySet."""
     9    widget = SelectMultiple
     10    hidden_widget = MultipleHiddenInput
     11    default_error_messages = {
     12        'invalid_list': _('Enter a list of values.'),
     13        'invalid_choice': _('Select a valid choice. %(value)s is not one of the'
     14                            ' available choices.'),
     15        'invalid_pk_value': _('ā€œ%(pk)sā€ is not a valid value.')
     16    }
     17    ...
     18
     19}}}
     20
     21
     22
     23{{{
     24class ModelChoiceField(ChoiceField):
     25    """A ChoiceField whose choices are a model QuerySet."""
     26    # This class is a subclass of ChoiceField for purity, but it doesn't
     27    # actually use any of ChoiceField's implementation.
     28    default_error_messages = {
     29        'invalid_choice': _('Select a valid choice. That choice is not one of'
     30                            ' the available choices.'),
     31    }
     32    ...
     33}}}
Back to Top