#32347: ModelChoiceField does not provide value of invalid choice when raising
ValidationError
--------------------------+--------------------------------------
     Reporter:  aawiegel  |                    Owner:  nobody
         Type:  Bug       |                   Status:  new
    Component:  Forms     |                  Version:  3.1
     Severity:  Normal    |               Resolution:
     Keywords:            |             Triage Stage:  Unreviewed
    Has patch:  0         |      Needs documentation:  0
  Needs tests:  0         |  Patch needs improvement:  0
Easy pickings:  1         |                    UI/UX:  0
--------------------------+--------------------------------------
Description changed by aawiegel:

Old description:

> Compared 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.

New description:

 Compared 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.

 From source code:


 {{{
 class ModelMultipleChoiceField(ModelChoiceField):
     """A MultipleChoiceField whose choices are a model QuerySet."""
     widget = SelectMultiple
     hidden_widget = MultipleHiddenInput
     default_error_messages = {
         'invalid_list': _('Enter a list of values.'),
         'invalid_choice': _('Select a valid choice. %(value)s is not one
 of the'
                             ' available choices.'),
         'invalid_pk_value': _('ā€œ%(pk)sā€ is not a valid value.')
     }
     ...

 }}}



 {{{
 class ModelChoiceField(ChoiceField):
     """A ChoiceField whose choices are a model QuerySet."""
     # This class is a subclass of ChoiceField for purity, but it doesn't
     # actually use any of ChoiceField's implementation.
     default_error_messages = {
         'invalid_choice': _('Select a valid choice. That choice is not one
 of'
                             ' the available choices.'),
     }
     ...
 }}}

--

-- 
Ticket URL: <https://code.djangoproject.com/ticket/32347#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/066.385f732781dabdaaeb637fb8bae2f486%40djangoproject.com.

Reply via email to