Django 'ManagementForm data is missing or has been tampered with' foreign manytomany foreign key

妖精的绣舞 提交于 2021-02-11 12:50:35

问题


I'm getting this error after submitting my form(it uses inlines and foreign keys).

This is a follow up to my question: How to save a model in ModelForm with two ForeignKey fields in Django

Now my views.py looks like this:

def CreateFlo(request):    
    EstadosInlineFormSet = inlineformset_factory(Listaflor, Flora2Estado, form=Flo2Form)
    floForm = FloForm(request.POST)
    if request.method == 'POST':
        if floForm.is_valid():
            new_flo = floForm.save()
            estadosInlineFormSet = EstadosInlineFormSet(request.POST, request.FILES, instance=new_flo)

            if estadosInlineFormSet.is_valid():
                estadosInlineFormSet.save()
        else:
            estadosInlineFormSet = EstadosInlineFormSet()
            floForm = FloForm()

    context = {'floForm': floForm}
    return render(request, 'accounts/enviar_flora.html', context)

enviar_flora.html:

<div class="form_page">
    <h3>{{texto}}</h3>
    <h2>Enviar Espécie</h2>
    <form action="" method="POST">
        {% csrf_token %}
        {{ floForm.as_table }}
        {{ floForm.management_form }}
        <input type="submit" name="Enviar" value="Enviar" id="enviar">
    </form>
</div>

full error: https://i.stack.imgur.com/rIaUz.png

来源:https://stackoverflow.com/questions/66013168/django-managementform-data-is-missing-or-has-been-tampered-with-foreign-manyto

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!