diff options
| author | Honza Král <honza.kral@gmail.com> | 2009-10-12 10:16:17 +0000 |
|---|---|---|
| committer | Honza Král <honza.kral@gmail.com> | 2009-10-12 10:16:17 +0000 |
| commit | dfe495fbe8e360ee3b3cd8b29e55ee19d86fc9d2 (patch) | |
| tree | 16bccad252c6fd2b00e734f275594ae159596e70 /docs/topics/forms | |
| parent | 83a3588ff712d5fe44e9692f5cb6a1d020f3ab2f (diff) | |
[soc2009/model-validation] Merged to trunk at r11603
SECURITY ALERT: Corrected regular expressions for URL and email fields.
git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/model-validation@11617 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs/topics/forms')
| -rw-r--r-- | docs/topics/forms/modelforms.txt | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/docs/topics/forms/modelforms.txt b/docs/topics/forms/modelforms.txt index add581268b..c5aa9c8a77 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 ---------------------------- @@ -512,6 +541,12 @@ Then, pass your ``BaseAuthorFormSet`` class to the factory function:: >>> AuthorFormSet = modelformset_factory(Author, formset=BaseAuthorFormSet) +If you want to return a formset that doesn't include *any* pre-existing +instances of the model, you can specify an empty QuerySet:: + + >>> AuthorFormSet(queryset=Author.objects.none()) + + Controlling which fields are used with ``fields`` and ``exclude`` ----------------------------------------------------------------- |
