Re: [Django] #8913: Make the "must be unique" error messages in ModelForms customizable

21 views
Skip to first unread message

Django

unread,
Jun 9, 2011, 5:26:35 AM6/9/11
to django-...@googlegroups.com
#8913: Make the "must be unique" error messages in ModelForms customizable
-------------------------------------+-------------------------------------
Reporter: | Owner: leahculver
Alexander_Nesterov | Status: new
Type: New | Component: Forms
feature | Severity: Normal
Milestone: | Keywords: forms, unique,
Version: 1.0 | validation
Resolution: | Has patch: 0
Triage Stage: Accepted | Needs tests: 0
Needs documentation: 0 | Easy pickings: 0
Patch needs improvement: 0 |
UI/UX: 0 |
-------------------------------------+-------------------------------------
Changes (by anonymous):

* owner: nobody => leahculver
* ui_ux: => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/8913#comment:9>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jun 9, 2011, 9:03:52 AM6/9/11
to django-...@googlegroups.com
#8913: Make the "must be unique" error messages in ModelForms customizable
-------------------------------------+-------------------------------------
Reporter: | Owner: leahculver
Alexander_Nesterov | Status: new
Type: New | Component: Forms
feature | Severity: Normal
Milestone: | Keywords: forms, unique,
Version: 1.0 | validation
Resolution: | Has patch: 1
Triage Stage: Accepted | Needs tests: 0
Needs documentation: 1 | Easy pickings: 0
Patch needs improvement: 1 |
UI/UX: 0 |
-------------------------------------+-------------------------------------
Changes (by leahculver):

* needs_better_patch: 0 => 1
* has_patch: 0 => 1
* needs_docs: 0 => 1


Comment:

I've added a rough patch for this. To specify a custom error message for
the unique contraint, you'll need to do something like this:

{{{
class Context(models.Model):
name = models.CharField(error_messages={'unique': u'My custom
message'})
}}}

I don't know a lot about !ModelForms vs. Forms but I can't seem to get
this to work for plain Forms. Should this also be a Form error_message
key?

I'm also not sure where to put the docs since the Model error_messages
parameter is documented but lacking specificity
(https://docs.djangoproject.com/en/1.3/ref/models/fields/#error-messages).
Should I make this more specific?

--
Ticket URL: <https://code.djangoproject.com/ticket/8913#comment:10>

Django

unread,
Jun 9, 2011, 9:51:17 AM6/9/11
to django-...@googlegroups.com
#8913: Make the "must be unique" error messages in ModelForms customizable
-------------------------------------+-------------------------------------
Reporter: | Owner: leahculver
Alexander_Nesterov | Status: new
Type: New | Component: Forms
feature | Severity: Normal
Milestone: | Keywords: forms, unique,
Version: 1.0 | validation
Resolution: | Has patch: 1
Triage Stage: Accepted | Needs tests: 0
Needs documentation: 1 | Easy pickings: 0
Patch needs improvement: 1 |
UI/UX: 0 |
-------------------------------------+-------------------------------------

Comment (by anonymous):

You've got a bare except on #168, with a ambiguous failure message. I'd
just remove that altogether.

--
Ticket URL: <https://code.djangoproject.com/ticket/8913#comment:11>

Django

unread,
Jun 9, 2011, 10:00:45 AM6/9/11
to django-...@googlegroups.com
#8913: Make the "must be unique" error messages in ModelForms customizable
-------------------------------------+-------------------------------------
Reporter: | Owner: leahculver
Alexander_Nesterov | Status: new
Type: New | Component: Forms
feature | Severity: Normal
Milestone: | Keywords: forms, unique,
Version: 1.0 | validation
Resolution: | Has patch: 1
Triage Stage: Accepted | Needs tests: 0
Needs documentation: 0 | Easy pickings: 0
Patch needs improvement: 1 |
UI/UX: 0 |
-------------------------------------+-------------------------------------
Changes (by leahculver):

* needs_docs: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/8913#comment:12>

Django

unread,
Jun 9, 2011, 10:04:41 AM6/9/11
to django-...@googlegroups.com
#8913: Make the "must be unique" error messages in ModelForms customizable
-------------------------------------+-------------------------------------
Reporter: | Owner: leahculver
Alexander_Nesterov | Status: new
Type: New | Component: Forms
feature | Severity: Normal
Milestone: | Keywords: forms, unique,
Version: 1.0 | validation
Resolution: | Has patch: 1
Triage Stage: Ready for | Needs tests: 0
checkin | Easy pickings: 0
Needs documentation: 0 |
Patch needs improvement: 0 |
UI/UX: 0 |
-------------------------------------+-------------------------------------
Changes (by andrewgodwin):

* needs_better_patch: 1 => 0
* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/8913#comment:13>

Django

unread,
Jun 9, 2011, 10:07:02 AM6/9/11
to django-...@googlegroups.com
#8913: Make the "must be unique" error messages in ModelForms customizable
-------------------------------------+-------------------------------------
Reporter: | Owner: leahculver
Alexander_Nesterov | Status: new
Type: New | Component: Forms
feature | Severity: Normal
Milestone: | Keywords: forms, unique,
Version: 1.0 | validation
Resolution: | Has patch: 1
Triage Stage: Ready for | Needs tests: 0
checkin | Easy pickings: 0
Needs documentation: 0 |
Patch needs improvement: 0 |
UI/UX: 0 |
-------------------------------------+-------------------------------------

Comment (by leahculver):

I've created a new ticket (#16192) for unique_together custom error
messages since this is more difficult.

--
Ticket URL: <https://code.djangoproject.com/ticket/8913#comment:14>

Django

unread,
Jun 9, 2011, 11:05:15 AM6/9/11
to django-...@googlegroups.com
#8913: Make the "must be unique" error messages in ModelForms customizable
-------------------------------------+-------------------------------------
Reporter: | Owner: leahculver
Alexander_Nesterov | Status: closed
Type: New | Component: Forms
feature | Severity: Normal
Milestone: | Keywords: forms, unique,
Version: 1.0 | validation
Resolution: fixed | Has patch: 1
Triage Stage: Ready for | Needs tests: 0
checkin | Easy pickings: 0
Needs documentation: 0 |
Patch needs improvement: 0 |
UI/UX: 0 |
-------------------------------------+-------------------------------------
Changes (by andrewgodwin):

* status: new => closed
* resolution: => fixed


Comment:

In [16345]:
{{{
#!CommitTicketReference repository="" revision="16345"
Fixed #8913 - Make "must be unique" error messages customisable. Thanks to
Leah Culver.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/8913#comment:15>

Django

unread,
Mar 22, 2012, 8:51:37 PM3/22/12
to django-...@googlegroups.com
#8913: Make the "must be unique" error messages in ModelForms customizable
-------------------------------------+-------------------------------------
Reporter: Alexander_Nesterov | Owner:
Type: Bug | leahculver
Component: Forms | Status: reopened
Severity: Normal | Version: SVN
Keywords: forms, unique, | Resolution:
validation | Triage Stage: Ready for
Has patch: 0 | checkin
Needs tests: 0 | Needs documentation: 0
Easy pickings: 0 | Patch needs improvement: 1
| UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Uznick <uznick@…>):

* status: closed => reopened
* cc: uznick@… (added)
* resolution: fixed =>
* version: 1.0 => SVN

* needs_better_patch: 0 => 1

* has_patch: 1 => 0
* type: New feature => Bug


Comment:

The error message is still not customizable when it's set in the
ModelForm.

Example:

{{{
class InformationSubscriber(models.Model):
email = models.EmailField(u"E-mail", unique=True)

class InformationSubscribeForm(forms.ModelForm):
email = forms.EmailField(label=u"E-mail", error_messages={'unique':
u"You are already subscribed to our news",})
}}}

When the form is submitted, the error is: Information Subscriber with this
E-mail already exists.

And when I set the error_messages in the Model, like

{{{
class InformationSubscriber(models.Model):
email = models.EmailField(u"E-mail", unique=True,
error_messages={'unique': u"You are already subscribed to our news",})

class InformationSubscribeForm(forms.ModelForm):
email = forms.EmailField(label=u"E-mail")
}}}
The error message is correct: You are already subscribed to our news.

But the problem is, that there should be an option to set a unique error
message on the form-level, not on the level of the whole model itself.

--
Ticket URL: <https://code.djangoproject.com/ticket/8913#comment:16>

Django

unread,
May 31, 2012, 3:04:38 AM5/31/12
to django-...@googlegroups.com
#8913: Make the "must be unique" error messages in ModelForms customizable
-------------------------------------+-------------------------------------
Reporter: Alexander_Nesterov | Owner:
Type: Bug | leahculver
Component: Forms | Status: closed
Severity: Normal | Version: master
Keywords: forms, unique, | Resolution: fixed
validation | Triage Stage: Ready for
Has patch: 0 | checkin
Needs tests: 0 | Needs documentation: 0
Easy pickings: 0 | Patch needs improvement: 1
| UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by claudep):

* status: reopened => closed
* resolution: => fixed


Comment:

I would suggest to open a new ticket, as allowing the message to be set on
the form level is a different story. Currently, validate_unique may
produce several errors to pass to !ValidationError, so we cannot simply
set code and params to be able to catch it at the form level.

--
Ticket URL: <https://code.djangoproject.com/ticket/8913#comment:17>

Reply all
Reply to author
Forward
0 new messages