diff -r 95d590521fb4 docs/ref/contrib/admin/index.txt
|
a
|
b
|
|
| 783 | 783 | ------------------------------------- |
| 784 | 784 | |
| 785 | 785 | Adding custom validation of data in the admin is quite easy. The automatic admin |
| 786 | | interfaces reuses :mod:`django.forms`, and the ``ModelAdmin`` class gives you |
| | 786 | interface reuses :mod:`django.forms`, and the ``ModelAdmin`` class gives you |
| 787 | 787 | the ability define your own form:: |
| 788 | 788 | |
| 789 | 789 | class ArticleAdmin(admin.ModelAdmin): |
| … |
… |
|
| 803 | 803 | |
| 804 | 804 | It is important you use a ``ModelForm`` here otherwise things can break. See the |
| 805 | 805 | :ref:`forms <ref-forms-index>` documentation on :ref:`custom validation |
| 806 | | <ref-forms-validation>` for more information. |
| | 806 | <ref-forms-validation>` and, more specifically, the |
| | 807 | :ref:`model form validation notes <overriding-modelform-clean-method>` for more |
| | 808 | information. |
| 807 | 809 | |
| 808 | 810 | .. _admin-inlines: |
| 809 | 811 | |
diff -r 95d590521fb4 docs/topics/forms/modelforms.txt
|
a
|
b
|
|
| 397 | 397 | ... model = Book |
| 398 | 398 | ... fields = ['title', 'author'] |
| 399 | 399 | |
| | 400 | .. _overriding-modelform-clean-method: |
| 400 | 401 | |
| 401 | 402 | Overriding the clean() method |
| 402 | 403 | ----------------------------- |
| 403 | 404 | |
| 404 | 405 | You can override the ``clean()`` method on a model form to provide additional |
| 405 | | validation in the same way you can on a normal form. However, by default the |
| 406 | | ``clean()`` method validates the uniqueness of fields that are marked as |
| 407 | | ``unique``, ``unique_together`` or ``unique_for_date|month|year`` on the model. |
| 408 | | Therefore, if you would like to override the ``clean()`` method and maintain the |
| 409 | | default validation, you must call the parent class's ``clean()`` method. |
| | 406 | validation in the same way you can on a normal form. |
| | 407 | |
| | 408 | In this regard, model forms have two specific characteristics when compared to |
| | 409 | forms: |
| | 410 | |
| | 411 | By default the ``clean()`` method validates the uniqueness of fields that are |
| | 412 | marked as ``unique``, ``unique_together`` or ``unique_for_date|month|year`` on |
| | 413 | the model. Therefore, if you would like to override the ``clean()`` method and |
| | 414 | maintain the default validation, you must call the parent class's ``clean()`` |
| | 415 | method. |
| | 416 | |
| | 417 | Also, a model form instance bound to a model object will contain a |
| | 418 | ``self.instance`` attribute that gives model form methods access to that |
| | 419 | specific model instance. |
| 410 | 420 | |
| 411 | 421 | Form inheritance |
| 412 | 422 | ---------------- |