summaryrefslogtreecommitdiff
path: root/docs/newforms.txt
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2007-08-06 04:52:14 +0000
committerAdrian Holovaty <adrian@holovaty.com>2007-08-06 04:52:14 +0000
commit89d4a5659401959d976baa807c8a1fc7fa92851f (patch)
treee662ebc9401b3c52ebc706b48b64e4b6dd405d54 /docs/newforms.txt
parent1474a5fd2c11a70890340e193b8801951f804ba5 (diff)
Edited docs/newforms.txt changes from [5804]
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5808 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs/newforms.txt')
-rw-r--r--docs/newforms.txt26
1 files changed, 17 insertions, 9 deletions
diff --git a/docs/newforms.txt b/docs/newforms.txt
index 718994678a..3a92193d44 100644
--- a/docs/newforms.txt
+++ b/docs/newforms.txt
@@ -1511,26 +1511,34 @@ exists in the database.
To work around this problem, every time you save a form using ``commit=False``,
Django adds a ``save_m2m()`` method to the form created by ``form_for_model``.
-After you have manually saved the instance produced by the form, you can invoke
-``save_m2m()`` to save the many-to-many form data::
+After you've manually saved the instance produced by the form, you can invoke
+``save_m2m()`` to save the many-to-many form data. For example::
# Create a form instance with POST data.
>>> f = AuthorForm(request.POST)
- # Create, but don't save the new author instance
+ # Create, but don't save the new author instance.
>>> new_author = f.save(commit=False)
- # Modify the author in some way
- ...
- # Save the new instance
+ # Modify the author in some way.
+ >>> new_author.some_field = 'some_value'
+
+ # Save the new instance.
>>> new_author.save()
- # Now save the many-to-many data for the form
+ # Now, save the many-to-many data for the form.
>>> f.save_m2m()
Calling ``save_m2m()`` is only required if you use ``save(commit=False)``.
-When you use a simple ``save()`` on a form, all data - include
-many-to-many data - is saved without the need for any additional method calls.
+When you use a simple ``save()`` on a form, all data -- including
+many-to-many data -- is saved without the need for any additional method calls.
+For example::
+
+ # Create a form instance with POST data.
+ >>> f = AuthorForm(request.POST)
+
+ # Create and save the new author instance. There's no need to do anything else.
+ >>> new_author = f.save()
Using an alternate base class
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~