Changeset 5808
- Timestamp:
- 08/05/07 23:52:14 (1 year ago)
- Files:
-
- django/trunk/docs/newforms.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/docs/newforms.txt
r5804 r5808 1512 1512 To work around this problem, every time you save a form using ``commit=False``, 1513 1513 Django adds a ``save_m2m()`` method to the form created by ``form_for_model``. 1514 After you have manually saved the instance produced by the form, you can invoke1515 ``save_m2m()`` to save the many-to-many form data ::1514 After you've manually saved the instance produced by the form, you can invoke 1515 ``save_m2m()`` to save the many-to-many form data. For example:: 1516 1516 1517 1517 # Create a form instance with POST data. 1518 1518 >>> f = AuthorForm(request.POST) 1519 1519 1520 # Create, but don't save the new author instance 1520 # Create, but don't save the new author instance. 1521 1521 >>> new_author = f.save(commit=False) 1522 1522 1523 # Modify the author in some way 1524 ... 1525 # Save the new instance 1523 # Modify the author in some way. 1524 >>> new_author.some_field = 'some_value' 1525 1526 # Save the new instance. 1526 1527 >>> new_author.save() 1527 1528 1528 # Now save the many-to-many data for the form1529 # Now, save the many-to-many data for the form. 1529 1530 >>> f.save_m2m() 1530 1531 1531 1532 Calling ``save_m2m()`` is only required if you use ``save(commit=False)``. 1532 When you use a simple ``save()`` on a form, all data - include 1533 many-to-many data - is saved without the need for any additional method calls. 1533 When you use a simple ``save()`` on a form, all data -- including 1534 many-to-many data -- is saved without the need for any additional method calls. 1535 For example:: 1536 1537 # Create a form instance with POST data. 1538 >>> f = AuthorForm(request.POST) 1539 1540 # Create and save the new author instance. There's no need to do anything else. 1541 >>> new_author = f.save() 1534 1542 1535 1543 Using an alternate base class
