Verschachtelte Django Formen: 'ManagementForm Daten fehlt oder manipuliert wurde'

So, ich habe umgeschaut, und es scheint, niemand hatte das gleiche problem, dass ich habe, um die Ursache dieser scheinbar häufiger Fehler. Ich bin der Wiedergabe einige Formulare in meinem html wie folgt:

<form method="post" action="">
{{ tags_formset.management_form }}

<!-- code displaying this formset -->
...
<!-- -->

    <form method="post" action="">
        {{ add_all_form.management_form }}
        {{ add_all_form.addTagsToAll }}
        <input type="submit" value="Add To Displayed Applicants" />
    </form>

    <form method="post" action="">
        {{ remove_all_form.management_form }}
        {{ remove_all_form.removeTagsFromAll }}
        <input type="submit" value="Remove From Displayed Applicants" />
    </form>
    <input type="submit" value="Save Changes" />
</form>

Wenn ich nicht die zwei inneren Formen der Formularsatz wird korrekt angezeigt und der submit-button funktioniert, das Formular zu senden. Wenn ich Hinzugefügt, der 2. zwei Formen ein paar Probleme aufgetreten:

-Der submit-button funktioniert nicht mehr (obwohl die EINGABETASTE drücken, während eine der Formularsatz der Felder ausgewählt ist, noch reicht die form

-Die add_all_form submit funktioniert, und es funktioniert propperly (kein problem, aber interessant in Bezug auf die nächste Punkt...)

-Die remove_all_form funktioniert nicht ad-throughs die "ManagementForm der Daten fehlt oder manipuliert wurde' Fehler bei der überprüfung.

Hier ist die views.py code, der erstellt dazu die Formen:

    TagsFormSet = formset_factory(TagsForm, formset=TagFormSet, extra=applicantQuery.count())
    if request.method == 'POST':
        tags_formset = TagsFormSet(request.POST, request.FILES, prefix='tags', applicants=applicantQuery)
        add_all_form = TagAddAllForm(request.POST, request.FILES, prefix='addForm', applicants=applicantQuery)
        remove_all_form = TagRemoveAllForm(request.POST, request.FILES, prefix='removeForm', applicants=applicantQuery)
        redirect = False
        if tags_formset.is_valid():
            for tagForm in tags_formset.forms:
                if 'tags' in tagForm.cleaned_data:
                    tagForm.saveTags()
                if 'removeTags' in tagForm.cleaned_data:
                    tagForm.deleteTags()                        
            redirect = True
        if add_all_form.is_valid():
            if 'addTagsToAll' in add_all_form.cleaned_data:
                add_all_form.saveTagsToAll()
            redirect = True
        if remove_all_form.is_valid():
            if 'removeTagsFromAll' in remove_all_form.cleaned_data:
                remove_all_form.deleteTagsFromAll()
            redirect = True
        if redirect:
            return http.HttpResponseRedirect('')
    else:
        initForms = []
        tags_formset = TagsFormSet(prefix='tags', applicants=applicantQuery)
        add_all_form = TagAddAllForm(prefix='addForm', applicants=applicantQuery)
        remove_all_form = TagRemoveAllForm(prefix='removeForm', applicants=applicantQuery)

Ich buchstäblich nicht herausfinden können, was schief läuft. Ich weiß nicht, warum die add_all_form funktioniert, wenn die remove_all_form nicht, wie ich im Grunde kopieren und klebte alles an (wenn Sie brauchen, kann ich nach den code aus der Forms.py Datei, aber ich glaube nicht, dass das problem da ist...)

Bitte um Hilfe!!

InformationsquelleAutor James | 2013-04-18
Schreibe einen Kommentar