Index: /home/tobryan1/workspace/django/docs/newforms.txt =================================================================== --- /home/tobryan1/workspace/django/docs/newforms.txt (revision 5478) +++ /home/tobryan1/workspace/django/docs/newforms.txt (working copy) @@ -1617,6 +1617,28 @@ this data is not bound to the form. You will need to bind data to the form before the form can be saved. +So, to edit an object already in the database, use the following pattern. In +the GET branch of your view, instantiate a form using ``form_for_instance`` and +display it on the page. In the POST branch, again use ``form_for_instance``, and +then bind the data to the form. Here's a short example: + + #typical view pattern + def edit_foo_by_id(request, foo_id): + foo = Foo.objects.get_object_or_404(id=foo_id) + FooForm = form_for_instance(foo) + if request.POST: + data = request.POST.copy() + f = FooForm(data) + if f.is_valid(): + f.save() + ... #probably redirect to result page + else: + #handle validation error + else: + #GET + f = FooForm() + ... #return response and display form + When you call ``save()`` on a form created by ``form_for_instance()``, the database instance will be updated. As in ``form_for_model()``, ``save()`` will raise ``ValueError`` if the data doesn't validate.