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 开发者_JAVA百科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
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))
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.
精彩评论