ManagementForm data is missing or has been tampered with. Missing fields: servicesprice_set-TOTAL_FORMS

Viewed 247

When i am changing and saving from Inclusive To Exclusive Django admin give me following error:

(Hidden field TOTAL_FORMS) This field is required.
(Hidden field INITIAL_FORMS) This field is required.

ManagementForm data is missing or has been tampered with. Missing fields: servicesprice_set-TOTAL_FORMS, 
    servicesprice_set-INITIAL_FORMS. You may need to file a bug report if the issue persists.

enter image description here

This is happening after i override inline field. What does this mean?

@admin.register(Services)
class ServicesAdmin(ImportExportModelAdmin, EmptyFieldListFilter):
    ...
    inlines = [
        SubServiceInline,
        ServicePriceInline
    ]

    ExclusiveInlines = [
        ExclusiveServicePriceInline
    ]
    InclusiveInlines = []

    ...
    def get_inlines(self, request, obj):
        if not obj.parent_id:
            return self.inlines
        elif obj.type == 1:
            return self.InclusiveInlines
        else:
            return self.ExclusiveInlines
1 Answers

I'm rather new here myself, but I've been struggling with the same issue today.

It turns out that MyModelAdmin.get_inline() is called before the MyModel.save() when you're saving via the admin panel like that.

This creates a conflict when you're adding an InlineAdmin for a related model that, in my case, wasn't created until the MyModel.save() function was called.

I hope that helps, and I wish I could explain it better. Just learning all of this, myself. :)

Good luck to you!

Related