summaryrefslogtreecommitdiff
path: root/docs/topics/forms/modelforms.txt
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2009-09-13 01:35:18 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2009-09-13 01:35:18 +0000
commit38e78da95efbef2689c7409c53cebbd6a0f3e41a (patch)
treec928478fd416ae657dd206b3eea6c0fd2dcbcfb9 /docs/topics/forms/modelforms.txt
parent0e07f80cf4cf05bbb14fa18cc0013f3cd66687f8 (diff)
Fixed #11740 -- Added extra detail on the behavior of ModelForms. Thanks to severian for the suggestion.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@11548 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs/topics/forms/modelforms.txt')
-rw-r--r--docs/topics/forms/modelforms.txt29
1 files changed, 29 insertions, 0 deletions
diff --git a/docs/topics/forms/modelforms.txt b/docs/topics/forms/modelforms.txt
index add581268b..3a0c2d175c 100644
--- a/docs/topics/forms/modelforms.txt
+++ b/docs/topics/forms/modelforms.txt
@@ -371,6 +371,35 @@ parameter when declaring the form field::
... class Meta:
... model = Article
+.. note::
+
+ If you explicitly instantiate a form field like this, Django assumes that you
+ want to completely define its behavior; therefore, default attributes (such as
+ ``max_length`` or ``required``) are not drawn from the corresponding model. If
+ you want to maintain the behavior specified in the model, you must set the
+ relevant arguments explicitly when declaring the form field.
+
+ For example, if the ``Article`` model looks like this::
+
+ class Article(models.Model):
+ headline = models.CharField(max_length=200, null=True, blank=True,
+ help_text="Use puns liberally")
+ content = models.TextField()
+
+ and you want to do some custom validation for ``headline``, while keeping
+ the ``blank`` and ``help_text`` values as specified, you might define
+ ``ArticleForm`` like this::
+
+ class ArticleForm(ModelForm):
+ headline = MyFormField(max_length=200, required=False,
+ help_text="Use puns liberally")
+
+ class Meta:
+ model = Article
+
+ See the :ref:`form field documentation <ref-forms-fields>` for more information
+ on fields and their arguments.
+
Changing the order of fields
----------------------------