summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorBrian Rosner <brosner@gmail.com>2008-08-04 19:29:33 +0000
committerBrian Rosner <brosner@gmail.com>2008-08-04 19:29:33 +0000
commitac6952089061e3e160cd6ae4487840593ac95575 (patch)
tree3f62cba4ed6c07bc8b822743ceb3a47490e5fab8 /docs
parentbf65fd0a8050891cf4155eef8dbbe3d364699748 (diff)
Added the missing form option to the ModelAdmin options section. Also added a section for custom validation in the admin.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@8208 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs')
-rw-r--r--docs/admin.txt32
1 files changed, 32 insertions, 0 deletions
diff --git a/docs/admin.txt b/docs/admin.txt
index 2894b1d57c..99c66152ad 100644
--- a/docs/admin.txt
+++ b/docs/admin.txt
@@ -69,6 +69,13 @@ Example::
date_hierarchy = 'pub_date'
+``form``
+~~~~~~~~
+
+The default ``forms.ModelForm`` class used to generate the form on the
+add/change pages for models. You can easily change this to your own
+``ModelForm`` to override the default form behavior of the add/change pages.
+
``fieldsets``
~~~~~~~~~~~~~
@@ -528,6 +535,31 @@ apply as `regular media definitions on forms`_.
.. _regular media definitions on forms: ../forms/#media
+Adding custom validation to the admin
+-------------------------------------
+
+Adding custom validation of data in the admin is quite easy. The automatic
+admin interfaces reuses the Django `forms`_ module. The ``ModelAdmin`` class
+gives you the ability define your own form::
+
+ class ArticleAdmin(admin.ModelAdmin):
+ form = MyArticleAdminForm
+
+``MyArticleAdminForm`` can be defined anywhere as long as you import where
+needed. Now within your form you can add your own custom validation for
+any field::
+
+ class MyArticleAdminForm(forms.ModelForm):
+ def clean_name(self):
+ # do something that validates your data
+ return self.cleaned_data["name"]
+
+It is important you use a ``ModelForm`` here otherwise things can break. See
+the `forms`_ documentation on `custom validation`_ for more information.
+
+.. _forms: ../forms/
+.. _custom validation: ../forms/#custom-form-and-field-validation
+
``InlineModelAdmin`` objects
============================