Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Facing similar problem, I've come to conclusion that it's not possible.</p> <p>Though having multiple forms per page itself turned out to be a design mistake, presenting all sorts of troubles. E.g., user fills two forms, clicks submit on one of them and loses data from the other. Workaround requires complicated controller that needs to be aware of the state of all forms on the page. (See also <a href="http://discuss.joelonsoftware.com/default.asp?design.4.363620.12" rel="noreferrer">here</a> for some discussion on related problem.) </p> <p>If having multiple forms per page isn't your exact requirement, I'd suggest to look at alternative solutions.</p> <p>For example, it's usually possible to show user only one <strong>editable</strong> form at a time.</p> <p>In my case, I switched to <code>django-formwizard</code> (<s>not a django.contrib one, which is a bit old and seems to be currently under a redesign, but <a href="http://github.com/stephrdev/django-formwizard" rel="noreferrer">this one</a></s> <em>Update:</em> Beginning with release 1.4 of Django, <code>django-formwizard</code> app will be available in <code>django.contrib</code>, replacing old formwizard. It's already in trunk, <a href="https://docs.djangoproject.com/en/dev/ref/contrib/formtools/form-wizard/" rel="noreferrer">see docs</a>). For the user I made it to look like there are actually multiple forms on the page, but only one is editable. And user had to fill forms in predetermined order. This made dealing with multiple forms much easier.</p> <p>Otherwise, if forms <em>really</em> need to be presented all at once, it may make sense to combine them into one.</p> <hr> <p>UPDATE (after your clarification):</p> <p>No, you can't deal with formsets using generic <code>FormView</code> either. Though your example appears to be quite simple to implement: I think it's very similar to <a href="https://docs.djangoproject.com/en/dev/topics/forms/formsets/#using-more-than-one-formset-in-a-view" rel="noreferrer">this example</a> in Django docs on formsets. It deals with two formsets, and you just need to replace one with the form (I think you still need to specify prefix to avoid possible clashes of elements' <code>id</code> attributes).</p> <p>In short, in your case I'd subclass <code>django.views.generic.base.View</code> and override <code>get()</code> and <code>post()</code> methods to deal with form and formset similar to above example from Django docs.</p> <p>In this case, I think it's fine to present both form and formset editable—with a single button to submit them both.</p> <p>ANOTHER UPDATE:</p> <p>There's an active recent ticket in Django trac, <a href="http://code.djangoproject.com/ticket/16256" rel="noreferrer"><code>#16256</code> More class based views: formsets derived generic views</a>. If all goes well, new generic views will be added to Django: <code>FormSetsView</code>, <code>ModelFormSetsView</code> and <code>InlineFormSetsView</code>. Particularly, the last one ‘provides a way to show and handle a model with it's inline formsets’.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload