summaryrefslogtreecommitdiff
path: root/docs/ref/models
diff options
context:
space:
mode:
authorJoseph Kocherhans <joseph@jkocherhans.com>2010-01-05 03:56:19 +0000
committerJoseph Kocherhans <joseph@jkocherhans.com>2010-01-05 03:56:19 +0000
commit471596fc1afcb9c6258d317c619eaf5fd394e797 (patch)
tree193767161be3cc23dc2e6be5e4f16d8fd21a2925 /docs/ref/models
parent4e89105d64bb9e04c409139a41e9c7aac263df4c (diff)
Merged soc2009/model-validation to trunk. Thanks, Honza!
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12098 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs/ref/models')
-rw-r--r--docs/ref/models/fields.txt22
-rw-r--r--docs/ref/models/instances.txt25
2 files changed, 47 insertions, 0 deletions
diff --git a/docs/ref/models/fields.txt b/docs/ref/models/fields.txt
index 3c1106a217..8612b742ef 100644
--- a/docs/ref/models/fields.txt
+++ b/docs/ref/models/fields.txt
@@ -196,6 +196,17 @@ callable it will be called every time a new object is created.
If ``False``, the field will not be editable in the admin or via forms
automatically generated from the model class. Default is ``True``.
+``error_messages``
+------------------
+
+.. versionadded:: 1.2
+
+.. attribute:: Field.error_messages
+
+The ``error_messages`` argument lets you override the default messages that the
+field will raise. Pass in a dictionary with keys matching the error messages you
+want to override.
+
``help_text``
-------------
@@ -284,6 +295,17 @@ underscores to spaces. See :ref:`Verbose field names <verbose-field-names>`.
.. _model-field-types:
+``validators``
+-------------------
+
+.. versionadded:: 1.2
+
+.. attribute:: Field.validators
+
+A list of validators to run for this field.See the :ref:`validators
+documentation <validators>` for more information.
+
+
Field types
===========
diff --git a/docs/ref/models/instances.txt b/docs/ref/models/instances.txt
index 7a0606dafe..43f18338a1 100644
--- a/docs/ref/models/instances.txt
+++ b/docs/ref/models/instances.txt
@@ -27,6 +27,31 @@ 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 its ``full_validate()`` method:
+
+.. method:: Model.full_validate([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
+``self.validate_unique()`` or the superclasses ``validate`` method 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
==============