Search code examples
pythonpython-3.xdjangodjango-adminnonetype

How to override and call super for response_change or response_add in django admin


I would like to override response_change in a ModelAdmin in order to update a field in the parent window. After doing the update, I'd like to give control back to the overriden response_change.

A simplified version of what I have tried is:

class MyModelAdmin(admin.ModelAdmin):
    def response_change(self, request, obj):
        // perfom my actions
        super(MyModelAdmin, self).response_change(request, obj)

But I get an AttributeError - 'NoneType' object has no attribute 'has_header'. Maybe, I'm not using super properly...?


Solution

  • You need to actually return the result of the call to super().

    return super(MyModelAdmin, self).response_change(request, obj)