summaryrefslogtreecommitdiff
path: root/docs/ref/validators.txt
diff options
context:
space:
mode:
authordjango-bot <ops@djangoproject.com>2023-03-01 13:35:43 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-03-01 13:39:03 +0100
commit62510f01e76ad0526c94ea6d1bc6399c1ddf3df4 (patch)
tree79844be246eba809a4ca09c6f4c3448f2276321a /docs/ref/validators.txt
parent32f224e359c68e70e3f9a230be0265dcd6677079 (diff)
[4.2.x] Fixed #34140 -- Reformatted code blocks in docs with blacken-docs.
Diffstat (limited to 'docs/ref/validators.txt')
-rw-r--r--docs/ref/validators.txt7
1 files changed, 5 insertions, 2 deletions
diff --git a/docs/ref/validators.txt b/docs/ref/validators.txt
index 3fd1db7ded..f63d100a26 100644
--- a/docs/ref/validators.txt
+++ b/docs/ref/validators.txt
@@ -18,11 +18,12 @@ For example, here's a validator that only allows even numbers::
from django.core.exceptions import ValidationError
from django.utils.translation import gettext_lazy as _
+
def validate_even(value):
if value % 2 != 0:
raise ValidationError(
- _('%(value)s is not an even number'),
- params={'value': value},
+ _("%(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`
@@ -30,6 +31,7 @@ argument::
from django.db import models
+
class MyModel(models.Model):
even_field = models.IntegerField(validators=[validate_even])
@@ -38,6 +40,7 @@ use the same validator with forms::
from django import forms
+
class MyForm(forms.Form):
even_field = forms.IntegerField(validators=[validate_even])