1
0
mirror of https://github.com/django/django.git synced 2025-11-07 07:15:35 +00:00

Fixed #16192 -- Made unique error messages in ModelForm customizable.

Overriding the error messages now works for both unique fields, unique_together
and unique_for_date.

This patch changed the overriding logic to allow customizing NON_FIELD_ERRORS
since previously only fields' errors were customizable.

Refs #20199.

Thanks leahculver for the suggestion.
This commit is contained in:
Loic Bistuer
2014-02-04 01:31:27 +07:00
committed by Tim Graham
parent 65131911db
commit 8847a0c601
11 changed files with 142 additions and 34 deletions

View File

@@ -484,6 +484,14 @@ Forms
that maps fields to their original errors, complete with all metadata
(error code and params), the latter returns the errors serialized as json.
* It's now possible to customize the error messages for ``ModelForm``s
``unique``, ``unique_for_date``, and ``unique_together`` constraints.
In order to support ``unique_together`` or any other ``NON_FIELD_ERROR``,
``ModelForm`` now looks for the ``NON_FIELD_ERROR`` key in the
``error_messages`` dictionary of the ``ModelForm``s inner ``Meta`` class.
See :ref:`considerations regarding model's error_messages
<considerations-regarding-model-errormessages>` for more details.
Internationalization
^^^^^^^^^^^^^^^^^^^^