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 ==============