summaryrefslogtreecommitdiff
path: root/docs/topics/forms/formsets.txt
diff options
context:
space:
mode:
authorBrian Rosner <brosner@gmail.com>2008-08-27 16:44:52 +0000
committerBrian Rosner <brosner@gmail.com>2008-08-27 16:44:52 +0000
commite704559e567c46d46fe9268147e1a4a2cf83f4a2 (patch)
tree6716b3be7aac0d93be07255bb5a7228202dcd8a0 /docs/topics/forms/formsets.txt
parentd441a758de854ed05b495f613a9baa47e098b4d5 (diff)
Fixed #8435 -- Documented the `prefix` option on formsets.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@8631 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs/topics/forms/formsets.txt')
-rw-r--r--docs/topics/forms/formsets.txt29
1 files changed, 29 insertions, 0 deletions
diff --git a/docs/topics/forms/formsets.txt b/docs/topics/forms/formsets.txt
index 5d1e3ed729..ca7aa2e14f 100644
--- a/docs/topics/forms/formsets.txt
+++ b/docs/topics/forms/formsets.txt
@@ -327,3 +327,32 @@ with the management form::
</form>
The above ends up calling the ``as_table`` method on the formset class.
+
+Using more than one formset in a view
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+You are able to use more than one formset in a view if you like. Formsets
+borrow much of its behavior from forms. With that said you are able to use
+``prefix`` to prefix formset form field names with a given value to allow
+more than one formset to be sent to a view without name clashing. Lets take
+a look at how this might be accomplished::
+
+ def manage_articles(request):
+ ArticleFormSet = formset_factory(ArticleForm)
+ BookFormSet = formset_factory(BookForm)
+ if request.method == 'POST':
+ article_formset = ArticleFormSet(request.POST, request.FILES, prefix='articles')
+ book_formset = BookFormSet(request.POST, request.FILES, prefix='books')
+ if article_formset.is_valid() and book_formset.is_valid():
+ # do something with the cleaned_data on the formsets.
+ else:
+ article_formset = ArticleFormSet(prefix='articles')
+ book_formset = BookFormSet(prefix='books')
+ return render_to_response('manage_articles.html', {
+ 'article_formset': article_formset,
+ 'book_formset': book_formset,
+ })
+
+You would then render the formsets as normal. It is important to point out
+that you need to pass ``prefix`` on both the POST and non-POST cases so that
+it is rendered and processed correctly.