[Django]-Django admin – prevent objects being saved, and don't show the user confirmation message

1πŸ‘

βœ…

I think you want to use the messages framework.

In an admin action:

class FooAdmin(admin.ModelAdmin):
    ....
    def foo_action(self, request, queryset):
        ....
        self.message_user(request, "%s foo objects were not saved" % foos_not_saved)

In a (model)form:

def save(*args, **kwargs):
    # do stuff
    self.message_user(request, "%s fields were not saved" % ','.join(fields_not_saved))
πŸ‘€shanyu

0πŸ‘

I believe the message is just js. The javascript for the admin site lives in djangoX.X/django/contrib/admin/media/js/ and I believe you can change the message in actions.js.

Alternatively you can go into djangoX.X/django/contrib/admin/templates/admin/ and over ride the js from there.

πŸ‘€Daniel Nill

Leave a comment