Author: brosner
Date: 2008-09-02 12:57:02 -0500 (Tue, 02 Sep 2008)
New Revision: 8863
Modified:
django/trunk/docs/topics/forms/modelforms.txt
Log:
Added some docs on model formsets in views.
Modified: django/trunk/docs/topics/forms/modelforms.txt
===================================================================
--- django/trunk/docs/topics/forms/modelforms.txt 2008-09-02 17:33:51 UTC
(rev 8862)
+++ django/trunk/docs/topics/forms/modelforms.txt 2008-09-02 17:57:02 UTC
(rev 8863)
@@ -495,6 +495,29 @@
<tr><th><label for="id_form-2-name">Name:</label></th><td><input
id="id_form-2-name" type="text" name="form-2-name" value="Walt Whitman"
maxlength="100" /><input type="hidden" name="form-2-id" value="2"
id="id_form-2-id" /></td></tr>
<tr><th><label for="id_form-3-name">Name:</label></th><td><input
id="id_form-3-name" type="text" name="form-3-name" maxlength="100" /><input
type="hidden" name="form-3-id" id="id_form-3-id" /></td></tr>
+Using a model formset in a view
+-------------------------------
+
+Model formsets are very similar to formsets. Lets say we want to present a
+formset to a user to edit ``Author`` model instances::
+
+ def manage_authors(request):
+ AuthorFormSet = modelformset_factory(Author)
+ if request.POST == 'POST':
+ formset = AuthorFormSet(request.POST, request.FILES)
+ if formset.is_valid():
+ formset.save()
+ # do something.
+ else:
+ formset = AuthorFormSet()
+ render_to_response("manage_authors.html", {
+ "formset": formset,
+ })
+
+As you can see the view is not drastically different than how to use a formset
+in a view. The only difference is that we call ``formset.save()`` to save the
+data into the database. This was describe above in
:ref:`ref-saving-objects-in-the-formset`.
+
Using ``inlineformset_factory``
-------------------------------
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---