#22105: Model error messages overwritten by modelform django defaults
-------------------------+-------------------------------------------------
     Reporter:           |      Owner:  Dr_White
  daniel@…               |     Status:  new
         Type:  Bug      |    Version:  master
    Component:  Forms    |   Keywords:  error_messages, model, error, form,
     Severity:  Normal   |  _update_errors
 Triage Stage:           |  Has patch:  0
  Unreviewed             |      UI/UX:  0
Easy pickings:  0        |
-------------------------+-------------------------------------------------
 Imagine a model with custom error messages added to some of it's fields.

 {{{
 from django.db import models


 class MyModel(models.Model):
     name = models.CharField(
         max_length=255,
         error_messages={
             'required': 'my required msg..',
         }
     )
 }}}

 When a modelform is created from this model

 {{{
 from django.forms import ModelForm
 from .models import MyModel


 class MyModelForm(ModelForm):

     class Meta:
         model = MyModel
         fields = ['name']
 }}}

 I would expect to see the custom error message.
 Instead the function _update_errors from BaseModelForm simply doesn't
 care, I quote:
     '''Override any validation error messages defined at the model level
 with those defined at the form level.'''

 I believe any custom error message defined in the model should take
 precedence over the default form messages.
 Whenever error messages also defined in the modelform meta like so:


 {{{
 class MyModelForm(ModelForm):

     class Meta:
         model = MyModel
         fields = ['name']
         error_messages = {
             'name': {
                 'required': "This is a custom error message from modelform
 meta",
             },
         }
 }}}

 Then the error message from the modelform should be used.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/22105>
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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/064.139e49ac31962fbf7f6ed6df66748550%40djangoproject.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to