Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango "ManagementForm data missing" when rendering 2 formsets with foreignkey
    text
    copied!<p>I am trying to render 2 formsets in 1 view and am getting a </p> <pre><code>u'ManagementForm data is missing or has been tampered with </code></pre> <p>error. The webpage is rendering fine and the data does pass the values to the database when I hit submit, but I think I am passing the management form data incorrectly. </p> <p>I also want to add that I used "<a href="https://docs.djangoproject.com/en/dev/topics/forms/formsets/" rel="nofollow">https://docs.djangoproject.com/en/dev/topics/forms/formsets/</a>" but it did not provide sufficient documentation on passing the management form data. Also, my options and outcome formsets have the same foreignkey. Let me know if you spot any trouble with passing the managementform data, or if there's anything else wrong with the code.</p> <p>Below is my views.py and html:</p> <p>views.py</p> <pre><code>def option(request): if request.method == "POST": optionForm = OptionForm(request.POST) outcomeForm = OutcomeForm(request.POST) if optionForm.is_valid(): new_option = optionForm.save() new_outcome = outcomeForm.save() optionInlineFormSet = OptionFormSet(request.POST, request.FILES, instance=new_option, prefix='option') outcomeInlineFormSet = OutcomeFormSet(request.POST, request.FILES, instance=new_outcome, prefix='outcome') if optionInlineFormSet.is_valid() and outcomeInlineFormSet.is_valid: optionInlineFormSet.save() outcomeInlineForSet.save() return HttpResponseRedirect(reverse(outcome)) else: optionForm = OptionForm() outcomeForm = OutcomeForm() optionInlineFormSet = OptionFormSet() outcomeInlineFormSet = OutcomeFormSet() return render_to_response("option.html", {'optionForm': optionForm, 'outcomeForm': outcomeForm, 'optionInlineFormSet': optionInlineFormSet, 'outcomeInlineFormSet': outcomeInlineFormSet}, context_instance=RequestContext(request)) </code></pre> <p>html:</p> <pre><code>&lt;form class="option_form" action="{% url option %}" method="post"&gt;{% csrf_token %} {{ optionInlineFormSet.management_form }} {{ outcomeInlineFormSet.management_form }} {{ optionForm.as_table }} {{ outcomeForm.as_table}} &lt;input type="submit" name="submit" value="Submit" class="button"&gt; &lt;/form&gt; </code></pre>
 

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