| 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 | |