From 69fef1daef3ce5a34bd7701f0f23765da5c926e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Honza=20Kr=C3=A1l?= Date: Wed, 12 Aug 2009 20:11:30 +0000 Subject: [PATCH] [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 --- docs/ref/models/instances.txt | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) 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 ==============