Kaydet (Commit) 866d7fa9 authored tarafından James Bennett's avatar James Bennett

Correct an example in docs/modelforms.txt, and fix some reST formatting


git-svn-id: http://code.djangoproject.com/svn/django/trunk@7222 bcc190cf-cafb-0310-a4f2-bffc1f526a37
üst 42712048
...@@ -226,7 +226,7 @@ For example:: ...@@ -226,7 +226,7 @@ For example::
# Create a form instance with POST data. # Create a form instance with POST data.
>>> a = Author() >>> a = Author()
>>> f = AuthorForm(a, request.POST) >>> f = AuthorForm(request.POST, instance=a)
# Create and save the new author instance. There's no need to do anything else. # Create and save the new author instance. There's no need to do anything else.
>>> new_author = f.save() >>> new_author = f.save()
...@@ -238,21 +238,21 @@ In some cases, you may not want all the model fields to appear on the generated ...@@ -238,21 +238,21 @@ In some cases, you may not want all the model fields to appear on the generated
form. There are three ways of telling ``ModelForm`` to use only a subset of the form. There are three ways of telling ``ModelForm`` to use only a subset of the
model fields: model fields:
1. Set ``editable=False`` on the model field. As a result, *any* form 1. Set ``editable=False`` on the model field. As a result, *any* form
created from the model via ``ModelForm`` will not include that created from the model via ``ModelForm`` will not include that
field. field.
2. Use the ``fields`` attribute of the ``ModelForm``'s inner ``Meta`` class. 2. Use the ``fields`` attribute of the ``ModelForm``'s inner ``Meta``
This attribute, if given, should be a list of field names to include in class. This attribute, if given, should be a list of field names
the form. to include in the form.
3. Use the ``exclude`` attribute of the ``ModelForm``'s inner ``Meta`` class. 3. Use the ``exclude`` attribute of the ``ModelForm``'s inner ``Meta``
This attribute, if given, should be a list of field names to exclude class. This attribute, if given, should be a list of field names
the form. to exclude the form.
For example, if you want a form for the ``Author`` model (defined above) For example, if you want a form for the ``Author`` model (defined
that includes only the ``name`` and ``title`` fields, you would specify above) that includes only the ``name`` and ``title`` fields, you would
``fields`` or ``exclude`` like this:: specify ``fields`` or ``exclude`` like this::
class PartialAuthorForm(ModelForm): class PartialAuthorForm(ModelForm):
class Meta: class Meta:
...@@ -264,8 +264,8 @@ model fields: ...@@ -264,8 +264,8 @@ model fields:
model = Author model = Author
exclude = ('birth_date',) exclude = ('birth_date',)
Since the Author model has only 3 fields, 'name', 'title', and Since the Author model has only 3 fields, 'name', 'title', and
'birth_date', the forms above will contain exactly the same fields. 'birth_date', the forms above will contain exactly the same fields.
.. note:: .. note::
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment