I need to add some pre- and post-save logic to my ModelAdmin, but only when the user submitted the form via the 'Save and continue editing' button and not the 'Save' button. How can I do this?
Just like overriding the normal save method, you need to override the save_model() function in your ModelAdmin, which includes the request object. From the request object you can get the POST object, which will include a '_continue' key if the user clicked the 'Save and continue button'. Example:
class MyAdmin(admin.ModelAdmin):
    def save_model(self, request, obj, form, changed):
        if '_continue' in request.POST:
            # add your code here
        return super(ServerAdmin, self).change_view(request, obj, form, changed)
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With