-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use model error_messages when available #3435
Conversation
In the automatically applied UniqueValidator, use the error message from error_messages defined in the model instead of the generic default UniqueValidator message. This fixes encode#2878.
Seems reasonable. |
Use model error_messages when available
unique_error_message = model_field.error_messages.get('unique', None) | ||
if unique_error_message: | ||
unique_error_message = unique_error_message % { | ||
'model_name': model_field.model._meta.object_name, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
django uses capfirst for verbose_name
would such change be accepted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most probably yup! (Could you point out an example of exactly where/what first tho?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what you would like to see. Is it this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect, yup. If you do choose to submit a fix for this it'll also be worth double checking if there's any other errors messages where we should also be doing capfirst(opts.verbose_name)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can it filter OneToOneField?
In the automatically applied UniqueValidator, use the error message from
error_messages defined in the model instead of the generic default
UniqueValidator message.
This fixes #2878.