Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You're right, those docs are not very useful. It's a recent addition after all!</p> <p>My guess is that the normal usage of error_messages is for ModelForms, so I'd look here for a list of acceptable error keys per field: <a href="http://docs.djangoproject.com/en/dev/ref/forms/fields/#error-messages" rel="noreferrer">http://docs.djangoproject.com/en/dev/ref/forms/fields/#error-messages</a></p> <p><strong>But, if you want to be really safe and not assume anything...</strong></p> <p>The most reliable way for now is going to be looking at the source at <code>django/db/models/fields/__init__.py</code> where you'll see each of the <code>default_error_messages</code> that can be specified and the actual calls to <code>self.error_messages['invalid']</code></p> <pre><code># Field (base class) default_error_messages = { 'invalid_choice': _(u'Value %r is not a valid choice.'), 'null': _(u'This field cannot be null.'), 'blank': _(u'This field cannot be blank.'), } # AutoField default_error_messages = { 'invalid': _(u'This value must be an integer.'), } </code></pre> <p>Here's the doc on model validation: <a href="http://docs.djangoproject.com/en/dev/ref/models/instances/#validating-objects" rel="noreferrer">http://docs.djangoproject.com/en/dev/ref/models/instances/#validating-objects</a></p> <h1>Update:</h1> <p>Just tested this in a shell session and it appears to be working. Whats up?</p> <p>I just defined a simple model:</p> <pre><code>class SubscriptionGroup(models.Model): name = models.CharField(max_length=255, error_messages={'blank': 'INVALID!!11', 'null': 'NULL11!'}) # shell &gt;&gt;&gt; s = SubscriptionGroup() &gt;&gt;&gt; s.full_clean() ValidationError: {'name': [u'INVALID!!11']} </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload