Feature Request: Customisation of constraint error messages in forms

112 views
Skip to first unread message

David Sanders

unread,
Sep 19, 2022, 1:52:00 PM9/19/22
to django-d...@googlegroups.com
Hi folks,


As part of Django's new constraint validation, constraints now get a violation_error_message to declare custom user-friendly error messages. Currently, UniqueConstraints with a single field can additionally have form-specific error messages set via forms' error_messages dictionary (or in model form fields). If it's decided that check constraints also raise field errors then they will also be specifically customisable in forms.

I'd like to propose that constraints raising non-field errors to also be specifically customisable in addition to the general default set in violation_error_message – To do this validation errors would need the `code` kwarg set.

One possibility is setting the code based on the constraint name.  Single-field unique constraints already set the code "unique"; and this works for field errors because there's usually only one unique constraint defined for a field.

Thoughts?

Cheers,
David
Reply all
Reply to author
Forward
0 new messages