Property changes on: /home/tobryan1/workspace/django ___________________________________________________________________ Name: svn:ignore - build dist *.egg-info MANIFEST + build dist *.egg-info MANIFEST .project .pydevproject Index: /home/tobryan1/workspace/django/docs/newforms.txt =================================================================== --- /home/tobryan1/workspace/django/docs/newforms.txt (revision 5595) +++ /home/tobryan1/workspace/django/docs/newforms.txt (working copy) @@ -1617,6 +1617,30 @@ 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. Get +the object for which you want to create a form in and use the +`form_for_instance` function to create a Form class. In the GET branch, +instantiate the class with no data, and it will use the values from the +instance as defaults. In the POST branch, instantiate the form using the POST +data and these will be saved to the database. 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.