summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHonza Král <honza.kral@gmail.com>2009-08-12 20:11:30 +0000
committerHonza Král <honza.kral@gmail.com>2009-08-12 20:11:30 +0000
commit69fef1daef3ce5a34bd7701f0f23765da5c926e6 (patch)
tree5a235d80279c25b117551e818fe1d03e405bc1db
parent2799e928432ba18ca77a74a5231833ba6d0f229c (diff)
downloaddjango-69fef1daef3ce5a34bd7701f0f23765da5c926e6.tar.gz
[soc2009/model-validation] A few words on validation methods on models
git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/model-validation@11439 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--docs/ref/models/instances.txt24
1 files changed, 24 insertions, 0 deletions
diff --git a/docs/ref/models/instances.txt b/docs/ref/models/instances.txt
index 7a0606dafe..ee5a607ff4 100644
--- a/docs/ref/models/instances.txt
+++ b/docs/ref/models/instances.txt
@@ -27,6 +27,30 @@ The keyword arguments are simply the names of the fields you've defined on your
model. Note that instantiating a model in no way touches your database; for
that, you need to ``save()``.
+Validating objects
+==================
+
+.. versionadded:: 1.2
+
+To validate your model, just call it's ``clean()`` method:
+
+.. method:: Model.clean([exclude=[]])
+
+The optional ``exclude`` argument can contain a list of field names that should
+be omitted when validating. This method raises ``ValidationError`` containing a
+message dict with errors from all fields.
+
+To add your own validation logic, override the supplied ``validate()`` method:
+
+.. method:: Model.validate()
+
+The ``validate()`` method on ``Model`` by default checks for uniqueness of
+fields and group of fields that are declared to be unique so remember to call
+``super.validate()`` if you want this validation to run.
+
+Any ``ValidationError`` raised in this method will be propagated in the
+``message_dict`` under ``NON_FIELD_ERRORS``.
+
Saving objects
==============