尝试在Django admin中显示自定义成功消息并隐藏默认成功消息

时间:2019-11-05 04:47:06

标签: django django-forms

<-- In admin.py I have a function it showing my custom message but also showing default success message how to stop default success message ??-->

from django.contrib import messages, admin
def save_model(self, request, obj, form, change):
  self.message_user(request, "The message", level=messages.SUCCESS)

1 个答案:

答案 0 :(得分:0)

尝试像这样在ModelAdmin中覆盖response_add方法

class YourModelAdmin(admin.ModelAdmin)
    .......
    def response_add(self, request, obj, post_url_continue=None):
        msg = "Your message"
        self.message_user(request, msg, level=messages.SUCCESS)
        return self.response_post_save_add(request, obj)