Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#18237 closed New feature (wontfix)

Custom error messages in ModelForm-s

Reported by: Karol Sikora Owned by: nobody
Component: Forms Version: 1.4
Severity: Normal Keywords: modelform, error messages
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

There should be a simple and dry way to override default error messages for ModelForms. According to #13693 and custom experience error_messages in field definitions does not working. One of solution is implementing something like http://blog.brendel.com/2012/01/django-modelforms-setting-any-field.html, but I definitely think that error_messages from model definition is the best way. Doing this by redefining fields in form breaks IMHO dry rules.

Change History (6)

comment:1 by Karol Sikora, 13 years ago

Component: UncategorizedForms

comment:2 by Jannis Leidel, 13 years ago

Resolution: wontfix
Status: newclosed

There is a simple way, subclass the form and override the error message by in a new form field. It's hardly a DRY violation if you want to modify the default behavior. The linked blog post proposes making the field params overridable by having more options in the Meta class, the worst possible API for form composing IMO. Closing as wontfix.

Version 0, edited 13 years ago by Jannis Leidel (next)

comment:3 by Karol Sikora, 13 years ago

Resolution: wontfix
Status: closedreopened

Defining form field to override error message is, in my opinion, hardly DRY violation. Maybe making field params overridable isn't good choice, but method that You proposed also isn't good. Why getting error messages form error_messages parameter in model definition is bad way? As I know these messages are used in admin, so there is the most intuitive way to set these messages also for model forms through error_messages in model definition. I don't agree with You to close this ticket, maybe it will be useful to get to know other's opinion.

comment:4 by Aymeric Augustin, 13 years ago

Resolution: wontfix
Status: reopenedclosed

If you disagree with a core developer who closed a ticket as wontfix, please make your case on the django-developers mailing list, in order to reach a wider audience. Thanks!

comment:6 by Carl Meyer, 13 years ago

Note that I just reopened #13693, which I believe would address the core use case here, without adding a Meta option.

Note: See TracTickets for help on using tickets.
Back to Top