Skip to content
Browse files

[1.1.X] Fixed #11740 -- Added extra detail on the behavior of ModelFo…

…rms. Thanks to severian for the suggestion.

Merge of r11548 from trunk.

git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent 05c0873 commit 2075da35251b3a98277287df721153bed9600dc0 @freakboy3742 freakboy3742 committed
Showing with 29 additions and 0 deletions.
  1. +29 −0 docs/topics/forms/modelforms.txt
29 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

0 comments on commit 2075da3

Please sign in to comment.
Something went wrong with that request. Please try again.