* 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.
* 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>
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>
* needs_docs: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/8913#comment:12>
* needs_better_patch: 1 => 0
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/8913#comment:13>
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>
* 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>
* 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>
* 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>