Brad
Brad

Reputation: 43

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

I want to prevent admins modifying certain data in django. I've done this, but when the user hits 'save', the data is correctly not saved, but the 'success' message is displayed at the top telling the user the data was updated. How can I replace this message?

Thanks

Upvotes: 4

Views: 1402

Answers (2)

shanyu
shanyu

Reputation: 9716

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))

Upvotes: 1

Daniel Nill
Daniel Nill

Reputation: 5747

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.

Upvotes: 0

Related Questions