[1.1.X] Fixed #11755 -- Added documentation for an edge case of FormSet usage. Thanks to ffualo for the suggestion.

Merge of r11549 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@11571 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Russell Keith-Magee 2009-09-13 06:33:35 +00:00
parent 2075da3525
commit d30dd3e9c9
1 changed files with 11 additions and 5 deletions

View File

@ -374,24 +374,24 @@ parameter when declaring the form field::
.. note:: .. note::
If you explicitly instantiate a form field like this, Django assumes that you If you explicitly instantiate a form field like this, Django assumes that you
want to completely define its behavior; therefore, default attributes (such as want to completely define its behavior; therefore, default attributes (such as
``max_length`` or ``required``) are not drawn from the corresponding model. If ``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 you want to maintain the behavior specified in the model, you must set the
relevant arguments explicitly when declaring the form field. relevant arguments explicitly when declaring the form field.
For example, if the ``Article`` model looks like this:: For example, if the ``Article`` model looks like this::
class Article(models.Model): class Article(models.Model):
headline = models.CharField(max_length=200, null=True, blank=True, headline = models.CharField(max_length=200, null=True, blank=True,
help_text="Use puns liberally") help_text="Use puns liberally")
content = models.TextField() content = models.TextField()
and you want to do some custom validation for ``headline``, while keeping and you want to do some custom validation for ``headline``, while keeping
the ``blank`` and ``help_text`` values as specified, you might define the ``blank`` and ``help_text`` values as specified, you might define
``ArticleForm`` like this:: ``ArticleForm`` like this::
class ArticleForm(ModelForm): class ArticleForm(ModelForm):
headline = MyFormField(max_length=200, required=False, headline = MyFormField(max_length=200, required=False,
help_text="Use puns liberally") help_text="Use puns liberally")
class Meta: class Meta:
@ -541,6 +541,12 @@ Then, pass your ``BaseAuthorFormSet`` class to the factory function::
>>> AuthorFormSet = modelformset_factory(Author, formset=BaseAuthorFormSet) >>> 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`` Controlling which fields are used with ``fields`` and ``exclude``
----------------------------------------------------------------- -----------------------------------------------------------------