mabeljuhi's picture

I am using the following code in my django app which is working fine but i am getting this error when trying to save a form:

['ManagementForm data is missing or has been tampered with']

Views:

def employedit(request, pk, id):
    employ_academic_forms = EmployAcademicUpdateFormSet(queryset=EmployAcademicInfo.objects.filter(employ_id=pk))
    if request.method == 'POST':
        employ_academic_forms = EmployAcademicUpdateFormSet(request.POST)
        if employ_academic_forms.is_valid():
            employ_academic_forms.save()
            return redirect('employ-list')
    context = {
        'employ_academic_forms':employ_academic_forms,
    }
    return render(request, 'admins/employ/edit_employ.html', context)

form:

EmployAcademicUpdateFormSet = modelformset_factory(
    EmployAcademicInfo,
    exclude = ['employ_id'],
    extra=0,
    labels = {
        'degree': 'Enter Employ Degree',
        'last_passing_institution_name': 'Enter Employ Passing Institution',
        'last_passing_year': 'Enter Employ Passing Year',
        
    },
    widgets = {
        'degree' : forms.Select(attrs={'class':'form-control form-control-lg', 'placeholder':'Enter degree'}),
        'last_passing_institution_name' : forms.TextInput(attrs={'class':'form-control form-control-lg', 'placeholder':'Enter institution name'}),
        'last_passing_year' : forms.DateInput(attrs={'class':'form-control form-control-lg', 'type':'date'}),
        
    },   
    )

Html:

{% extends 'base/base.html' %} 
{% load static %}
{% load crispy_forms_tags %} 
{% block content %}
<div class="card">
    <form class="form-horizontal" action="" method="post">
        {% csrf_token %}
        <div class="card-body">
            <div class="card-body">
                <div class="form-horizontal">
                        {{ employAcademicFormSet.management_form }}
                        {% for form in employ_academic_forms %} 
                        {% for field in form.visible_fields %}
                            <div class="form-group row">
                                <label class="col-md-3 col-form-label" for="text-input"><h6>{{ field.label_tag }}</h6></label>
                                <div class="col-md-9">{{ field }}</div>
                            </div>
                        {% endfor %} 
                        {% endfor %}
                    </div>
            </div>
        </div>
        <div class="card-footer">
            <button class="btn btn-lg btn-primary" type="submit">Submit</button>
        </div>
    </form>
</div>
{% endblock %}

Does anyone know what is causing this? Please help me!!!

Forum: 
Jeremy Davis's picture

Are you using TurnKey for starters? If so which version? How have you structured your code?

Also, you might even find your issue answered if you google the explicit error message.

So please respond with further info and if you find a solution in the meantime, please also post back with your solution. :)

Add new comment