summaryrefslogtreecommitdiff
path: root/docs/ref/forms/validation.txt
diff options
context:
space:
mode:
authorMarc Tamlyn <marc.tamlyn@gmail.com>2013-05-19 05:26:13 -0700
committerMarc Tamlyn <marc.tamlyn@gmail.com>2013-05-19 05:26:13 -0700
commitc6855e8a704a8fadee8fc0eefcd99c5dc5372ab2 (patch)
tree62cecfa131e9bd5b08caaaccc823ac2b75d9d932 /docs/ref/forms/validation.txt
parentc28b79580493f4bf5df9bea88a5c6bddfe27a6d6 (diff)
parent1fe587d80bfcf062a94252fb532c8ac035c833b9 (diff)
Merge pull request #1162 from sspross/patch-docs
Add needed Imports to the Documentation, Part II
Diffstat (limited to 'docs/ref/forms/validation.txt')
-rw-r--r--docs/ref/forms/validation.txt9
1 files changed, 9 insertions, 0 deletions
diff --git a/docs/ref/forms/validation.txt b/docs/ref/forms/validation.txt
index 3aaa69b6ea..87c9764f64 100644
--- a/docs/ref/forms/validation.txt
+++ b/docs/ref/forms/validation.txt
@@ -183,6 +183,9 @@ the ``default_validators`` attribute.
Simple validators can be used to validate values inside the field, let's have
a look at Django's ``SlugField``::
+ from django.forms import CharField
+ from django.core import validators
+
class SlugField(CharField):
default_validators = [validators.validate_slug]
@@ -252,6 +255,8 @@ we want to make sure that the ``recipients`` field always contains the address
don't want to put it into the general ``MultiEmailField`` class. Instead, we
write a cleaning method that operates on the ``recipients`` field, like so::
+ from django import forms
+
class ContactForm(forms.Form):
# Everything as before.
...
@@ -289,6 +294,8 @@ common method is to display the error at the top of the form. To create such
an error, you can raise a ``ValidationError`` from the ``clean()`` method. For
example::
+ from django import forms
+
class ContactForm(forms.Form):
# Everything as before.
...
@@ -321,6 +328,8 @@ here and leaving it up to you and your designers to work out what works
effectively in your particular situation. Our new code (replacing the previous
sample) looks like this::
+ from django import forms
+
class ContactForm(forms.Form):
# Everything as before.
...