Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[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: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@11570 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 2075da35251b3a98277287df721153bed9600dc0 1 parent 05c0873
Russell Keith-Magee authored September 13, 2009

Showing 1 changed file with 29 additions and 0 deletions. Show diff stats Hide diff stats

  1. 29  docs/topics/forms/modelforms.txt
29  docs/topics/forms/modelforms.txt
@@ -371,6 +371,35 @@ parameter when declaring the form field::
371 371
    ...     class Meta:
372 372
    ...         model = Article
373 373
 
  374
+.. note::
  375
+
  376
+    If you explicitly instantiate a form field like this, Django assumes that you
  377
+    want to completely define its behavior; therefore, default attributes (such as 
  378
+    ``max_length`` or ``required``) are not drawn from the corresponding model. If 
  379
+    you want to maintain the behavior specified in the model, you must set the
  380
+    relevant arguments explicitly when declaring the form field.
  381
+
  382
+    For example, if the ``Article`` model looks like this::
  383
+
  384
+        class Article(models.Model):
  385
+            headline = models.CharField(max_length=200, null=True, blank=True, 
  386
+                                        help_text="Use puns liberally")
  387
+            content = models.TextField()
  388
+
  389
+    and you want to do some custom validation for ``headline``, while keeping
  390
+    the ``blank`` and ``help_text`` values as specified, you might define 
  391
+    ``ArticleForm`` like this::
  392
+
  393
+        class ArticleForm(ModelForm):
  394
+            headline = MyFormField(max_length=200, required=False, 
  395
+                                   help_text="Use puns liberally")
  396
+
  397
+            class Meta:
  398
+                model = Article
  399
+
  400
+    See the :ref:`form field documentation <ref-forms-fields>` for more information
  401
+    on fields and their arguments.
  402
+
374 403
 Changing the order of fields
375 404
 ----------------------------
376 405
 

0 notes on commit 2075da3

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