mirror of
https://github.com/django/django.git
synced 2025-02-24 17:15:03 +00:00
Made some edits to the validation part of docs/ref/models/instances.txt
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12124 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
50bfa46c39
commit
d8b7772fca
@ -34,31 +34,30 @@ Validating objects
|
|||||||
|
|
||||||
.. versionadded:: 1.2
|
.. versionadded:: 1.2
|
||||||
|
|
||||||
To validate your model, just call its ``full_validate()`` method:
|
To validate your model, call its ``full_validate()`` method:
|
||||||
|
|
||||||
.. method:: Model.full_validate([exclude=[]])
|
.. method:: Model.full_validate([exclude=[]])
|
||||||
|
|
||||||
The optional ``exclude`` argument can contain a list of field names that should
|
The optional ``exclude`` argument can contain a list of field names to omit
|
||||||
be omitted when validating. This method raises ``ValidationError`` containing a
|
when validating. This method raises ``ValidationError`` containing a
|
||||||
message dict with errors from all fields.
|
message dictionary with errors from all fields.
|
||||||
|
|
||||||
To add your own validation logic, override the supplied ``validate()`` method:
|
To add your own validation logic, override the supplied ``validate()`` method:
|
||||||
|
|
||||||
Note that ``full_validate`` will NOT be called automatically when you call
|
Note that ``full_validate`` will NOT be called automatically when you call
|
||||||
your model's ``save()`` method. You will need to call it manually if you wish
|
your model's ``save()`` method. You'll need to call it manually if you want
|
||||||
to run your model validators. This is for the purposes of backwards
|
to run your model validators. (This is for backwards compatibility.) However,
|
||||||
compatibility. However, if you are using a ``ModelForm``, it will call
|
if you're using a ``ModelForm``, it will call ``full_validate`` for you and
|
||||||
``full_validate`` for you, and present any errors along with the other form
|
will present any errors along with the other form error messages.
|
||||||
error messages.
|
|
||||||
|
|
||||||
.. method:: Model.validate()
|
.. method:: Model.validate()
|
||||||
|
|
||||||
The ``validate()`` method on ``Model`` by default checks for uniqueness of
|
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
|
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
|
``self.validate_unique()`` or the superclass' ``validate`` method if you want
|
||||||
this validation to run.
|
this validation to run.
|
||||||
|
|
||||||
Any ``ValidationError`` raised in this method will be propagated in the
|
Any ``ValidationError`` raised in this method will be included in the
|
||||||
``message_dict`` under ``NON_FIELD_ERRORS``.
|
``message_dict`` under ``NON_FIELD_ERRORS``.
|
||||||
|
|
||||||
Saving objects
|
Saving objects
|
||||||
|
Loading…
x
Reference in New Issue
Block a user