diff options
| author | Jon Dufresne <jon.dufresne@gmail.com> | 2016-02-16 20:17:37 -0800 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-02-17 09:07:11 -0500 |
| commit | 61f1b6ff219a72902c81135ad4fb1db190f103f6 (patch) | |
| tree | ea98ff01c4be01b35fd39779735fcbfad0085c12 | |
| parent | 205cafd01ebe0f1c72ef3772a1b3f195387f4c50 (diff) | |
[1.9.x] Followed recommended ValidationError use in docs.
Backport of 0db7e61076116c2d93d61f98ef31690542359e48 from master
| -rw-r--r-- | docs/howto/custom-model-fields.txt | 3 | ||||
| -rw-r--r-- | docs/ref/validators.txt | 6 |
2 files changed, 7 insertions, 2 deletions
diff --git a/docs/howto/custom-model-fields.txt b/docs/howto/custom-model-fields.txt index 375b4c1e93..3485c8a22e 100644 --- a/docs/howto/custom-model-fields.txt +++ b/docs/howto/custom-model-fields.txt @@ -464,6 +464,7 @@ instances:: from django.core.exceptions import ValidationError from django.db import models + from django.utils.translation import ugettext_lazy as _ def parse_hand(hand_string): """Takes a string of cards and splits into a full hand.""" @@ -471,7 +472,7 @@ instances:: p2 = re.compile('..') args = [p2.findall(x) for x in p1.findall(hand_string)] if len(args) != 4: - raise ValidationError("Invalid input for a Hand instance") + raise ValidationError(_("Invalid input for a Hand instance")) return Hand(*args) class HandField(models.Field): diff --git a/docs/ref/validators.txt b/docs/ref/validators.txt index dcb68a6791..61dee0844a 100644 --- a/docs/ref/validators.txt +++ b/docs/ref/validators.txt @@ -16,10 +16,14 @@ different types of fields. For example, here's a validator that only allows even numbers:: from django.core.exceptions import ValidationError + from django.utils.translation import ugettext_lazy as _ def validate_even(value): if value % 2 != 0: - raise ValidationError('%s is not an even number' % value) + raise ValidationError( + _('%(value)s is not an even number'), + params={'value': value}, + ) You can add this to a model field via the field's :attr:`~django.db.models.Field.validators` argument:: |
