[Answer]-Better UI messages when aborting saving in Django admin

1👍

Overwirte the response_add(self, request, obj, post_url_continue=None) method of your admin class.

Have a look on the original ModelAdmin.response_add in django/contrib/admin/options.py

Here is a very basic example of a model admin that overwrites the messages after adding and changing instances.

class AmodelAdmin(admin.ModelAdmin):
    ...
    def response_add(self, request, obj, post_url_continue=None):
        from django.core.urlresolvers import reverse
        msg = "DON'T CLICK THIS BUTTON!"
        self.message_user(request, msg, level=messages.WARNING)
        return self.response_post_save_add(request, obj)

    def response_change(self, request, obj):)
        msg = "DON'T CLICK THIS BUTTON!"
        self.message_user(request, msg, level=messages.WARNING)
        return self.response_post_save_change(request, obj)
👤kanu

Leave a comment