Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango - Working with multiple forms
    primarykey
    data
    text
    <p>What I'm trying to do is to manage several forms in one page, I know there are formsets, and I know how the form management works, but I got some problems with the idea I have in mind.</p> <p>Just to help you to imagine what my problem is I'm going to use the django example models:</p> <pre><code>from django.db import models class Poll(models.Model): question = models.CharField(max_length=200) pub_date = models.DateTimeField() class Choice(models.Model): poll = models.ForeignKey(Poll) choice = models.CharField(max_length=200) votes = models.IntegerField(default=0) </code></pre> <p>Now, imagine I've already made the form clases:</p> <pre><code>from django import forms from mysite.polls.models import Poll, Choice class PollForm(forms.ModelForm): class Meta: model = Poll class ChoiceForm(forms.ModelForm): class Meta: model = Choice exclude = ('poll',) </code></pre> <p>So what I want to do is to have several form instances of the Poll and Choice model in a single page, but mind that these models can be repeated too:</p> <pre><code>&lt;form action="{{url}}" method="post"&gt; {{pollform}} {{choiceform}} {{pollform}} &lt;/form&gt; </code></pre> <p>As you can see there are two Poll forms and one Choice form, but the Poll forms are separated by the Choice form. I do need that the forms keep their order in the page, so is a little harder to use formsets. </p> <p>The problem I got, is that the values that comes in the post are all by the name "answer", so I get a list of all the elements from all forms by the name "answer" and I can't identify which ones belong to each form.</p> <p>Don't know if this explanation get a clear view of my problem. Any ideas to get this stuff done?</p> <p>Thanks for your help!</p> <p>PD: Don't pay attention to the relation between Poll and Choice, those models are just to clarify the problen, so the relation doesn't matter at all. </p>
    singulars
    1. This table or related slice is empty.
    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.
 

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