Django Crispy forms - inline Formsets 'ManagementForm data' error with update view











up vote
4
down vote

favorite












Good Evening,



Im having trouble with a crispy forms inlineformset. I have followed guides as per:



https://github.com/timhughes/django-cbv-inline-formset/blob/master/music/views.py
https://django-crispy-forms.readthedocs.io/en/latest/crispy_tag_formsets.html#formsets



EDIT
I think the issue is something to do with the dual submit buttons. the devicemodel form has a button that when pressed produces this error. but there is also a save button as part of the resource helper, when that's submitted I get an empty model form error.



I've added screenshots of what happens when you action each button



Error when resource save button pressed



error when update device button is pressed



and I must be missing something as am getting the error:



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


here is my update view:



class EditDeviceModel(PermissionRequiredMixin, SuccessMessageMixin, UpdateView):
model = DeviceModel
form_class = DeviceModelForm

template_name = "app_settings/base_formset.html"
permission_required = 'config.change_devicemodel'
success_message = 'Device Type "%(model)s" saved successfully'

def get_success_url(self, **kwargs):
return '{}#device_models'.format(reverse("config:config_settings"))

def get_success_message(self, cleaned_data):
return self.success_message % dict(
cleaned_data,
model=self.object.model,
)

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['title']='Edit Device Model'
if self.request.POST:
context['formset'] = DeviceFormSet(self.request.POST, instance=self.object)
else:
context['formset'] = DeviceFormSet(instance=self.object)
context['helper'] = DeviceFormSetHelper()
return context

def form_valid(self, form):
context = self.get_context_data()
formset = context['formset']
if formset.is_valid():
self.object = form.save()
formset.instance = self.object
formset.save()
return redirect(self.success_url)
else:
return self.render_to_response(self.get_context_data(form=form))


Here are my forms:



class MonitoredResourceForm(forms.ModelForm):
class Meta:
model = MonitoredResource
fields = ['resource','model']

def __init__(self, *args, **kwargs):
self.is_add = kwargs.pop("is_add", False)
super(MonitoredResourceForm, self).__init__(*args, **kwargs)
self.helper = FormHelper(self)
self.helper.form_id = 'snmp_resource_form'
self.helper.form_method = 'POST'
self.helper.layout = Layout(
Div(
Div(
Field('model'),
Field('resource', placeholder="Resource"),
css_class='col-lg-3'
),
css_class='row'
),
Div(
Div(
HTML("""<input type="submit" name="submit" value="""),
HTML('"Add' if self.is_add else '"Update' ),
HTML(""" monitored resource" class="btn btn-primary"/>"""),
HTML("""<a href="{% url 'config:config_settings' %}#monitored_resources" class="btn btn-primary">Cancel</a>"""),
HTML("""{% if object %}
<a href="{% url 'config:delete_monitoredresource' object.id %}"
class="btn btn-danger">
Delete <i class="fa fa-trash-o" aria-hidden="true"></i></a>
{% endif %}"""),
css_class='col-lg-12'
),
css_class='row'
),
)

class DeviceModelForm(forms.ModelForm):
class Meta:
model = DeviceModel
fields = ['model','vendor','device_type','ports','uplink_speed']

def __init__(self, *args, **kwargs):
self.is_add = kwargs.pop("is_add", False)
super(DeviceModelForm, self).__init__(*args, **kwargs)
self.helper = FormHelper(self)
self.helper.form_id = 'device_type_form'
self.helper.form_method = 'POST'
self.helper.layout = Layout(
Div(
Div(
Field('model', placeholder="Model"),
Field('vendor',),
Field('device_type',),
Field('ports', placeholder="Ports"),
Field('uplink_speed', placeholder="Uplink Speed"),
css_class='col-lg-6'
),
css_class='row'
),
Div(
Div(
HTML("""<input type="submit" name="submit" value="""),
HTML('"Add' if self.is_add else '"Update' ),
HTML(""" Device Model" class="btn btn-primary"/>"""),
HTML("""<a href="{% url 'config:config_settings' %}#device_models" class="btn btn-primary">Cancel</a>"""),
HTML("""{% if object %}
<a href="{% url 'config:delete_device_model' object.id %}"
class="btn btn-danger">
Delete <i class="fa fa-trash-o" aria-hidden="true"></i></a>
{% endif %}"""),
css_class='col-lg-12'
),
css_class='row'
),
)

DeviceFormSet = inlineformset_factory(DeviceModel, MonitoredResource, form=MonitoredResourceForm, extra=1)

class DeviceFormSetHelper(FormHelper):
def __init__(self, *args, **kwargs):
super(DeviceFormSetHelper, self).__init__(*args, **kwargs)
self.form_method = 'post'
self.render_required_fields = True
self.form_id = 'snmp_resource_form'
self.form_method = 'POST'
self.add_input(Submit("submit", "Save"))
self.layout = Layout(
Div(
Div(
Field('model'),
Field('resource', placeholder="Resource"),
css_class='col-lg-6'
),
css_class='row'
),
)


and in the templates I render:



{% block content %} 
{% include "home/form_errors.html" %}
<div class="col-lg-6">
{% crispy form %}
</div>
<div class="col-lg-6">
{% crispy formset helper %}
</div>
<!-- /.row -->
{% endblock %}


is anyone able to see what im missing?










share|improve this question
























  • share your project code in zip somewhere if you can.
    – Ashfaq Ahmed
    Dec 3 at 21:35















up vote
4
down vote

favorite












Good Evening,



Im having trouble with a crispy forms inlineformset. I have followed guides as per:



https://github.com/timhughes/django-cbv-inline-formset/blob/master/music/views.py
https://django-crispy-forms.readthedocs.io/en/latest/crispy_tag_formsets.html#formsets



EDIT
I think the issue is something to do with the dual submit buttons. the devicemodel form has a button that when pressed produces this error. but there is also a save button as part of the resource helper, when that's submitted I get an empty model form error.



I've added screenshots of what happens when you action each button



Error when resource save button pressed



error when update device button is pressed



and I must be missing something as am getting the error:



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


here is my update view:



class EditDeviceModel(PermissionRequiredMixin, SuccessMessageMixin, UpdateView):
model = DeviceModel
form_class = DeviceModelForm

template_name = "app_settings/base_formset.html"
permission_required = 'config.change_devicemodel'
success_message = 'Device Type "%(model)s" saved successfully'

def get_success_url(self, **kwargs):
return '{}#device_models'.format(reverse("config:config_settings"))

def get_success_message(self, cleaned_data):
return self.success_message % dict(
cleaned_data,
model=self.object.model,
)

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['title']='Edit Device Model'
if self.request.POST:
context['formset'] = DeviceFormSet(self.request.POST, instance=self.object)
else:
context['formset'] = DeviceFormSet(instance=self.object)
context['helper'] = DeviceFormSetHelper()
return context

def form_valid(self, form):
context = self.get_context_data()
formset = context['formset']
if formset.is_valid():
self.object = form.save()
formset.instance = self.object
formset.save()
return redirect(self.success_url)
else:
return self.render_to_response(self.get_context_data(form=form))


Here are my forms:



class MonitoredResourceForm(forms.ModelForm):
class Meta:
model = MonitoredResource
fields = ['resource','model']

def __init__(self, *args, **kwargs):
self.is_add = kwargs.pop("is_add", False)
super(MonitoredResourceForm, self).__init__(*args, **kwargs)
self.helper = FormHelper(self)
self.helper.form_id = 'snmp_resource_form'
self.helper.form_method = 'POST'
self.helper.layout = Layout(
Div(
Div(
Field('model'),
Field('resource', placeholder="Resource"),
css_class='col-lg-3'
),
css_class='row'
),
Div(
Div(
HTML("""<input type="submit" name="submit" value="""),
HTML('"Add' if self.is_add else '"Update' ),
HTML(""" monitored resource" class="btn btn-primary"/>"""),
HTML("""<a href="{% url 'config:config_settings' %}#monitored_resources" class="btn btn-primary">Cancel</a>"""),
HTML("""{% if object %}
<a href="{% url 'config:delete_monitoredresource' object.id %}"
class="btn btn-danger">
Delete <i class="fa fa-trash-o" aria-hidden="true"></i></a>
{% endif %}"""),
css_class='col-lg-12'
),
css_class='row'
),
)

class DeviceModelForm(forms.ModelForm):
class Meta:
model = DeviceModel
fields = ['model','vendor','device_type','ports','uplink_speed']

def __init__(self, *args, **kwargs):
self.is_add = kwargs.pop("is_add", False)
super(DeviceModelForm, self).__init__(*args, **kwargs)
self.helper = FormHelper(self)
self.helper.form_id = 'device_type_form'
self.helper.form_method = 'POST'
self.helper.layout = Layout(
Div(
Div(
Field('model', placeholder="Model"),
Field('vendor',),
Field('device_type',),
Field('ports', placeholder="Ports"),
Field('uplink_speed', placeholder="Uplink Speed"),
css_class='col-lg-6'
),
css_class='row'
),
Div(
Div(
HTML("""<input type="submit" name="submit" value="""),
HTML('"Add' if self.is_add else '"Update' ),
HTML(""" Device Model" class="btn btn-primary"/>"""),
HTML("""<a href="{% url 'config:config_settings' %}#device_models" class="btn btn-primary">Cancel</a>"""),
HTML("""{% if object %}
<a href="{% url 'config:delete_device_model' object.id %}"
class="btn btn-danger">
Delete <i class="fa fa-trash-o" aria-hidden="true"></i></a>
{% endif %}"""),
css_class='col-lg-12'
),
css_class='row'
),
)

DeviceFormSet = inlineformset_factory(DeviceModel, MonitoredResource, form=MonitoredResourceForm, extra=1)

class DeviceFormSetHelper(FormHelper):
def __init__(self, *args, **kwargs):
super(DeviceFormSetHelper, self).__init__(*args, **kwargs)
self.form_method = 'post'
self.render_required_fields = True
self.form_id = 'snmp_resource_form'
self.form_method = 'POST'
self.add_input(Submit("submit", "Save"))
self.layout = Layout(
Div(
Div(
Field('model'),
Field('resource', placeholder="Resource"),
css_class='col-lg-6'
),
css_class='row'
),
)


and in the templates I render:



{% block content %} 
{% include "home/form_errors.html" %}
<div class="col-lg-6">
{% crispy form %}
</div>
<div class="col-lg-6">
{% crispy formset helper %}
</div>
<!-- /.row -->
{% endblock %}


is anyone able to see what im missing?










share|improve this question
























  • share your project code in zip somewhere if you can.
    – Ashfaq Ahmed
    Dec 3 at 21:35













up vote
4
down vote

favorite









up vote
4
down vote

favorite











Good Evening,



Im having trouble with a crispy forms inlineformset. I have followed guides as per:



https://github.com/timhughes/django-cbv-inline-formset/blob/master/music/views.py
https://django-crispy-forms.readthedocs.io/en/latest/crispy_tag_formsets.html#formsets



EDIT
I think the issue is something to do with the dual submit buttons. the devicemodel form has a button that when pressed produces this error. but there is also a save button as part of the resource helper, when that's submitted I get an empty model form error.



I've added screenshots of what happens when you action each button



Error when resource save button pressed



error when update device button is pressed



and I must be missing something as am getting the error:



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


here is my update view:



class EditDeviceModel(PermissionRequiredMixin, SuccessMessageMixin, UpdateView):
model = DeviceModel
form_class = DeviceModelForm

template_name = "app_settings/base_formset.html"
permission_required = 'config.change_devicemodel'
success_message = 'Device Type "%(model)s" saved successfully'

def get_success_url(self, **kwargs):
return '{}#device_models'.format(reverse("config:config_settings"))

def get_success_message(self, cleaned_data):
return self.success_message % dict(
cleaned_data,
model=self.object.model,
)

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['title']='Edit Device Model'
if self.request.POST:
context['formset'] = DeviceFormSet(self.request.POST, instance=self.object)
else:
context['formset'] = DeviceFormSet(instance=self.object)
context['helper'] = DeviceFormSetHelper()
return context

def form_valid(self, form):
context = self.get_context_data()
formset = context['formset']
if formset.is_valid():
self.object = form.save()
formset.instance = self.object
formset.save()
return redirect(self.success_url)
else:
return self.render_to_response(self.get_context_data(form=form))


Here are my forms:



class MonitoredResourceForm(forms.ModelForm):
class Meta:
model = MonitoredResource
fields = ['resource','model']

def __init__(self, *args, **kwargs):
self.is_add = kwargs.pop("is_add", False)
super(MonitoredResourceForm, self).__init__(*args, **kwargs)
self.helper = FormHelper(self)
self.helper.form_id = 'snmp_resource_form'
self.helper.form_method = 'POST'
self.helper.layout = Layout(
Div(
Div(
Field('model'),
Field('resource', placeholder="Resource"),
css_class='col-lg-3'
),
css_class='row'
),
Div(
Div(
HTML("""<input type="submit" name="submit" value="""),
HTML('"Add' if self.is_add else '"Update' ),
HTML(""" monitored resource" class="btn btn-primary"/>"""),
HTML("""<a href="{% url 'config:config_settings' %}#monitored_resources" class="btn btn-primary">Cancel</a>"""),
HTML("""{% if object %}
<a href="{% url 'config:delete_monitoredresource' object.id %}"
class="btn btn-danger">
Delete <i class="fa fa-trash-o" aria-hidden="true"></i></a>
{% endif %}"""),
css_class='col-lg-12'
),
css_class='row'
),
)

class DeviceModelForm(forms.ModelForm):
class Meta:
model = DeviceModel
fields = ['model','vendor','device_type','ports','uplink_speed']

def __init__(self, *args, **kwargs):
self.is_add = kwargs.pop("is_add", False)
super(DeviceModelForm, self).__init__(*args, **kwargs)
self.helper = FormHelper(self)
self.helper.form_id = 'device_type_form'
self.helper.form_method = 'POST'
self.helper.layout = Layout(
Div(
Div(
Field('model', placeholder="Model"),
Field('vendor',),
Field('device_type',),
Field('ports', placeholder="Ports"),
Field('uplink_speed', placeholder="Uplink Speed"),
css_class='col-lg-6'
),
css_class='row'
),
Div(
Div(
HTML("""<input type="submit" name="submit" value="""),
HTML('"Add' if self.is_add else '"Update' ),
HTML(""" Device Model" class="btn btn-primary"/>"""),
HTML("""<a href="{% url 'config:config_settings' %}#device_models" class="btn btn-primary">Cancel</a>"""),
HTML("""{% if object %}
<a href="{% url 'config:delete_device_model' object.id %}"
class="btn btn-danger">
Delete <i class="fa fa-trash-o" aria-hidden="true"></i></a>
{% endif %}"""),
css_class='col-lg-12'
),
css_class='row'
),
)

DeviceFormSet = inlineformset_factory(DeviceModel, MonitoredResource, form=MonitoredResourceForm, extra=1)

class DeviceFormSetHelper(FormHelper):
def __init__(self, *args, **kwargs):
super(DeviceFormSetHelper, self).__init__(*args, **kwargs)
self.form_method = 'post'
self.render_required_fields = True
self.form_id = 'snmp_resource_form'
self.form_method = 'POST'
self.add_input(Submit("submit", "Save"))
self.layout = Layout(
Div(
Div(
Field('model'),
Field('resource', placeholder="Resource"),
css_class='col-lg-6'
),
css_class='row'
),
)


and in the templates I render:



{% block content %} 
{% include "home/form_errors.html" %}
<div class="col-lg-6">
{% crispy form %}
</div>
<div class="col-lg-6">
{% crispy formset helper %}
</div>
<!-- /.row -->
{% endblock %}


is anyone able to see what im missing?










share|improve this question















Good Evening,



Im having trouble with a crispy forms inlineformset. I have followed guides as per:



https://github.com/timhughes/django-cbv-inline-formset/blob/master/music/views.py
https://django-crispy-forms.readthedocs.io/en/latest/crispy_tag_formsets.html#formsets



EDIT
I think the issue is something to do with the dual submit buttons. the devicemodel form has a button that when pressed produces this error. but there is also a save button as part of the resource helper, when that's submitted I get an empty model form error.



I've added screenshots of what happens when you action each button



Error when resource save button pressed



error when update device button is pressed



and I must be missing something as am getting the error:



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


here is my update view:



class EditDeviceModel(PermissionRequiredMixin, SuccessMessageMixin, UpdateView):
model = DeviceModel
form_class = DeviceModelForm

template_name = "app_settings/base_formset.html"
permission_required = 'config.change_devicemodel'
success_message = 'Device Type "%(model)s" saved successfully'

def get_success_url(self, **kwargs):
return '{}#device_models'.format(reverse("config:config_settings"))

def get_success_message(self, cleaned_data):
return self.success_message % dict(
cleaned_data,
model=self.object.model,
)

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['title']='Edit Device Model'
if self.request.POST:
context['formset'] = DeviceFormSet(self.request.POST, instance=self.object)
else:
context['formset'] = DeviceFormSet(instance=self.object)
context['helper'] = DeviceFormSetHelper()
return context

def form_valid(self, form):
context = self.get_context_data()
formset = context['formset']
if formset.is_valid():
self.object = form.save()
formset.instance = self.object
formset.save()
return redirect(self.success_url)
else:
return self.render_to_response(self.get_context_data(form=form))


Here are my forms:



class MonitoredResourceForm(forms.ModelForm):
class Meta:
model = MonitoredResource
fields = ['resource','model']

def __init__(self, *args, **kwargs):
self.is_add = kwargs.pop("is_add", False)
super(MonitoredResourceForm, self).__init__(*args, **kwargs)
self.helper = FormHelper(self)
self.helper.form_id = 'snmp_resource_form'
self.helper.form_method = 'POST'
self.helper.layout = Layout(
Div(
Div(
Field('model'),
Field('resource', placeholder="Resource"),
css_class='col-lg-3'
),
css_class='row'
),
Div(
Div(
HTML("""<input type="submit" name="submit" value="""),
HTML('"Add' if self.is_add else '"Update' ),
HTML(""" monitored resource" class="btn btn-primary"/>"""),
HTML("""<a href="{% url 'config:config_settings' %}#monitored_resources" class="btn btn-primary">Cancel</a>"""),
HTML("""{% if object %}
<a href="{% url 'config:delete_monitoredresource' object.id %}"
class="btn btn-danger">
Delete <i class="fa fa-trash-o" aria-hidden="true"></i></a>
{% endif %}"""),
css_class='col-lg-12'
),
css_class='row'
),
)

class DeviceModelForm(forms.ModelForm):
class Meta:
model = DeviceModel
fields = ['model','vendor','device_type','ports','uplink_speed']

def __init__(self, *args, **kwargs):
self.is_add = kwargs.pop("is_add", False)
super(DeviceModelForm, self).__init__(*args, **kwargs)
self.helper = FormHelper(self)
self.helper.form_id = 'device_type_form'
self.helper.form_method = 'POST'
self.helper.layout = Layout(
Div(
Div(
Field('model', placeholder="Model"),
Field('vendor',),
Field('device_type',),
Field('ports', placeholder="Ports"),
Field('uplink_speed', placeholder="Uplink Speed"),
css_class='col-lg-6'
),
css_class='row'
),
Div(
Div(
HTML("""<input type="submit" name="submit" value="""),
HTML('"Add' if self.is_add else '"Update' ),
HTML(""" Device Model" class="btn btn-primary"/>"""),
HTML("""<a href="{% url 'config:config_settings' %}#device_models" class="btn btn-primary">Cancel</a>"""),
HTML("""{% if object %}
<a href="{% url 'config:delete_device_model' object.id %}"
class="btn btn-danger">
Delete <i class="fa fa-trash-o" aria-hidden="true"></i></a>
{% endif %}"""),
css_class='col-lg-12'
),
css_class='row'
),
)

DeviceFormSet = inlineformset_factory(DeviceModel, MonitoredResource, form=MonitoredResourceForm, extra=1)

class DeviceFormSetHelper(FormHelper):
def __init__(self, *args, **kwargs):
super(DeviceFormSetHelper, self).__init__(*args, **kwargs)
self.form_method = 'post'
self.render_required_fields = True
self.form_id = 'snmp_resource_form'
self.form_method = 'POST'
self.add_input(Submit("submit", "Save"))
self.layout = Layout(
Div(
Div(
Field('model'),
Field('resource', placeholder="Resource"),
css_class='col-lg-6'
),
css_class='row'
),
)


and in the templates I render:



{% block content %} 
{% include "home/form_errors.html" %}
<div class="col-lg-6">
{% crispy form %}
</div>
<div class="col-lg-6">
{% crispy formset helper %}
</div>
<!-- /.row -->
{% endblock %}


is anyone able to see what im missing?







django django-forms django-crispy-forms






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 30 at 15:17

























asked Nov 19 at 17:30









AlexW

44511153




44511153












  • share your project code in zip somewhere if you can.
    – Ashfaq Ahmed
    Dec 3 at 21:35


















  • share your project code in zip somewhere if you can.
    – Ashfaq Ahmed
    Dec 3 at 21:35
















share your project code in zip somewhere if you can.
– Ashfaq Ahmed
Dec 3 at 21:35




share your project code in zip somewhere if you can.
– Ashfaq Ahmed
Dec 3 at 21:35












3 Answers
3






active

oldest

votes

















up vote
1
down vote













I think you have to render management form in your template, explained here why you need that



Management Form is used by the formset to manage the collection of forms contained in the formset. If you don’t provide this management data, an exception will be raised



add this in view html



{{ DeviceFormSet.management_form }}





share|improve this answer























  • how do I fix my current issue? I tried adding {{ formset.management_form }} to the template but it hasn't worked
    – AlexW
    Nov 29 at 13:41












  • ive aded my DeviceForm and MonitoredResourceForm, I think it may be something to do with it creating seperate forms and submits for each model maybe?
    – AlexW
    Nov 29 at 17:50










  • can you share the version of Django you are using ?
    – Ashfaq Ahmed
    Nov 29 at 19:26










  • im using version 1.11.9
    – AlexW
    Nov 30 at 9:49










  • @AlexW have you added it like {{ DeviceFormSet.management_form }} same in template ? if not please try to add it as per the update answer.
    – Ashfaq Ahmed
    Nov 30 at 14:37




















up vote
0
down vote













You are missing a tag and also {{format.management_form|crispy}}
I guess






share|improve this answer





















  • Also is always nice to include a Form tag with post method to parent form.and management form is must
    – Rakon_188
    Nov 24 at 9:30












  • what tag? from what I understand from the crispy docs its correct? django-crispy-forms.readthedocs.io/en/latest/…
    – AlexW
    Nov 26 at 11:46










  • ive aded my DeviceForm and MonitoredResourceForm, I think it may be something to do with it creating seperate forms and submits for each model maybe?
    – AlexW
    Nov 29 at 17:50


















up vote
0
down vote













Your problem is that each form in a formset has its own management_form. I haven't dealt with this specifically in crispy, but in the general formsets, that was the problem that I had. You have to manually spell out each piece of the formset, either by iteration or hardcoding, and make sure that each has its management_form.






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53379841%2fdjango-crispy-forms-inline-formsets-managementform-data-error-with-update-vi%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote













    I think you have to render management form in your template, explained here why you need that



    Management Form is used by the formset to manage the collection of forms contained in the formset. If you don’t provide this management data, an exception will be raised



    add this in view html



    {{ DeviceFormSet.management_form }}





    share|improve this answer























    • how do I fix my current issue? I tried adding {{ formset.management_form }} to the template but it hasn't worked
      – AlexW
      Nov 29 at 13:41












    • ive aded my DeviceForm and MonitoredResourceForm, I think it may be something to do with it creating seperate forms and submits for each model maybe?
      – AlexW
      Nov 29 at 17:50










    • can you share the version of Django you are using ?
      – Ashfaq Ahmed
      Nov 29 at 19:26










    • im using version 1.11.9
      – AlexW
      Nov 30 at 9:49










    • @AlexW have you added it like {{ DeviceFormSet.management_form }} same in template ? if not please try to add it as per the update answer.
      – Ashfaq Ahmed
      Nov 30 at 14:37

















    up vote
    1
    down vote













    I think you have to render management form in your template, explained here why you need that



    Management Form is used by the formset to manage the collection of forms contained in the formset. If you don’t provide this management data, an exception will be raised



    add this in view html



    {{ DeviceFormSet.management_form }}





    share|improve this answer























    • how do I fix my current issue? I tried adding {{ formset.management_form }} to the template but it hasn't worked
      – AlexW
      Nov 29 at 13:41












    • ive aded my DeviceForm and MonitoredResourceForm, I think it may be something to do with it creating seperate forms and submits for each model maybe?
      – AlexW
      Nov 29 at 17:50










    • can you share the version of Django you are using ?
      – Ashfaq Ahmed
      Nov 29 at 19:26










    • im using version 1.11.9
      – AlexW
      Nov 30 at 9:49










    • @AlexW have you added it like {{ DeviceFormSet.management_form }} same in template ? if not please try to add it as per the update answer.
      – Ashfaq Ahmed
      Nov 30 at 14:37















    up vote
    1
    down vote










    up vote
    1
    down vote









    I think you have to render management form in your template, explained here why you need that



    Management Form is used by the formset to manage the collection of forms contained in the formset. If you don’t provide this management data, an exception will be raised



    add this in view html



    {{ DeviceFormSet.management_form }}





    share|improve this answer














    I think you have to render management form in your template, explained here why you need that



    Management Form is used by the formset to manage the collection of forms contained in the formset. If you don’t provide this management data, an exception will be raised



    add this in view html



    {{ DeviceFormSet.management_form }}






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 30 at 14:36

























    answered Nov 28 at 23:00









    Ashfaq Ahmed

    1,08831528




    1,08831528












    • how do I fix my current issue? I tried adding {{ formset.management_form }} to the template but it hasn't worked
      – AlexW
      Nov 29 at 13:41












    • ive aded my DeviceForm and MonitoredResourceForm, I think it may be something to do with it creating seperate forms and submits for each model maybe?
      – AlexW
      Nov 29 at 17:50










    • can you share the version of Django you are using ?
      – Ashfaq Ahmed
      Nov 29 at 19:26










    • im using version 1.11.9
      – AlexW
      Nov 30 at 9:49










    • @AlexW have you added it like {{ DeviceFormSet.management_form }} same in template ? if not please try to add it as per the update answer.
      – Ashfaq Ahmed
      Nov 30 at 14:37




















    • how do I fix my current issue? I tried adding {{ formset.management_form }} to the template but it hasn't worked
      – AlexW
      Nov 29 at 13:41












    • ive aded my DeviceForm and MonitoredResourceForm, I think it may be something to do with it creating seperate forms and submits for each model maybe?
      – AlexW
      Nov 29 at 17:50










    • can you share the version of Django you are using ?
      – Ashfaq Ahmed
      Nov 29 at 19:26










    • im using version 1.11.9
      – AlexW
      Nov 30 at 9:49










    • @AlexW have you added it like {{ DeviceFormSet.management_form }} same in template ? if not please try to add it as per the update answer.
      – Ashfaq Ahmed
      Nov 30 at 14:37


















    how do I fix my current issue? I tried adding {{ formset.management_form }} to the template but it hasn't worked
    – AlexW
    Nov 29 at 13:41






    how do I fix my current issue? I tried adding {{ formset.management_form }} to the template but it hasn't worked
    – AlexW
    Nov 29 at 13:41














    ive aded my DeviceForm and MonitoredResourceForm, I think it may be something to do with it creating seperate forms and submits for each model maybe?
    – AlexW
    Nov 29 at 17:50




    ive aded my DeviceForm and MonitoredResourceForm, I think it may be something to do with it creating seperate forms and submits for each model maybe?
    – AlexW
    Nov 29 at 17:50












    can you share the version of Django you are using ?
    – Ashfaq Ahmed
    Nov 29 at 19:26




    can you share the version of Django you are using ?
    – Ashfaq Ahmed
    Nov 29 at 19:26












    im using version 1.11.9
    – AlexW
    Nov 30 at 9:49




    im using version 1.11.9
    – AlexW
    Nov 30 at 9:49












    @AlexW have you added it like {{ DeviceFormSet.management_form }} same in template ? if not please try to add it as per the update answer.
    – Ashfaq Ahmed
    Nov 30 at 14:37






    @AlexW have you added it like {{ DeviceFormSet.management_form }} same in template ? if not please try to add it as per the update answer.
    – Ashfaq Ahmed
    Nov 30 at 14:37














    up vote
    0
    down vote













    You are missing a tag and also {{format.management_form|crispy}}
    I guess






    share|improve this answer





















    • Also is always nice to include a Form tag with post method to parent form.and management form is must
      – Rakon_188
      Nov 24 at 9:30












    • what tag? from what I understand from the crispy docs its correct? django-crispy-forms.readthedocs.io/en/latest/…
      – AlexW
      Nov 26 at 11:46










    • ive aded my DeviceForm and MonitoredResourceForm, I think it may be something to do with it creating seperate forms and submits for each model maybe?
      – AlexW
      Nov 29 at 17:50















    up vote
    0
    down vote













    You are missing a tag and also {{format.management_form|crispy}}
    I guess






    share|improve this answer





















    • Also is always nice to include a Form tag with post method to parent form.and management form is must
      – Rakon_188
      Nov 24 at 9:30












    • what tag? from what I understand from the crispy docs its correct? django-crispy-forms.readthedocs.io/en/latest/…
      – AlexW
      Nov 26 at 11:46










    • ive aded my DeviceForm and MonitoredResourceForm, I think it may be something to do with it creating seperate forms and submits for each model maybe?
      – AlexW
      Nov 29 at 17:50













    up vote
    0
    down vote










    up vote
    0
    down vote









    You are missing a tag and also {{format.management_form|crispy}}
    I guess






    share|improve this answer












    You are missing a tag and also {{format.management_form|crispy}}
    I guess







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 24 at 9:24









    Rakon_188

    4501614




    4501614












    • Also is always nice to include a Form tag with post method to parent form.and management form is must
      – Rakon_188
      Nov 24 at 9:30












    • what tag? from what I understand from the crispy docs its correct? django-crispy-forms.readthedocs.io/en/latest/…
      – AlexW
      Nov 26 at 11:46










    • ive aded my DeviceForm and MonitoredResourceForm, I think it may be something to do with it creating seperate forms and submits for each model maybe?
      – AlexW
      Nov 29 at 17:50


















    • Also is always nice to include a Form tag with post method to parent form.and management form is must
      – Rakon_188
      Nov 24 at 9:30












    • what tag? from what I understand from the crispy docs its correct? django-crispy-forms.readthedocs.io/en/latest/…
      – AlexW
      Nov 26 at 11:46










    • ive aded my DeviceForm and MonitoredResourceForm, I think it may be something to do with it creating seperate forms and submits for each model maybe?
      – AlexW
      Nov 29 at 17:50
















    Also is always nice to include a Form tag with post method to parent form.and management form is must
    – Rakon_188
    Nov 24 at 9:30






    Also is always nice to include a Form tag with post method to parent form.and management form is must
    – Rakon_188
    Nov 24 at 9:30














    what tag? from what I understand from the crispy docs its correct? django-crispy-forms.readthedocs.io/en/latest/…
    – AlexW
    Nov 26 at 11:46




    what tag? from what I understand from the crispy docs its correct? django-crispy-forms.readthedocs.io/en/latest/…
    – AlexW
    Nov 26 at 11:46












    ive aded my DeviceForm and MonitoredResourceForm, I think it may be something to do with it creating seperate forms and submits for each model maybe?
    – AlexW
    Nov 29 at 17:50




    ive aded my DeviceForm and MonitoredResourceForm, I think it may be something to do with it creating seperate forms and submits for each model maybe?
    – AlexW
    Nov 29 at 17:50










    up vote
    0
    down vote













    Your problem is that each form in a formset has its own management_form. I haven't dealt with this specifically in crispy, but in the general formsets, that was the problem that I had. You have to manually spell out each piece of the formset, either by iteration or hardcoding, and make sure that each has its management_form.






    share|improve this answer

























      up vote
      0
      down vote













      Your problem is that each form in a formset has its own management_form. I haven't dealt with this specifically in crispy, but in the general formsets, that was the problem that I had. You have to manually spell out each piece of the formset, either by iteration or hardcoding, and make sure that each has its management_form.






      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        Your problem is that each form in a formset has its own management_form. I haven't dealt with this specifically in crispy, but in the general formsets, that was the problem that I had. You have to manually spell out each piece of the formset, either by iteration or hardcoding, and make sure that each has its management_form.






        share|improve this answer












        Your problem is that each form in a formset has its own management_form. I haven't dealt with this specifically in crispy, but in the general formsets, that was the problem that I had. You have to manually spell out each piece of the formset, either by iteration or hardcoding, and make sure that each has its management_form.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 6 at 5:03









        rchurch4

        1766




        1766






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53379841%2fdjango-crispy-forms-inline-formsets-managementform-data-error-with-update-vi%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

            Alcedinidae

            RAC Tourist Trophy