cp151
cp151

Reputation: 197

Modifying the warning message when deleting an object in django admin?

I would like to add some stuff to the confirmation message on django admin ? The one that shows up and says "Hei, if you delete that you'll delete that and that and that too..."

Does anyone have an idea ?

Upvotes: 3

Views: 2359

Answers (1)

frnhr
frnhr

Reputation: 12903

django admin uses default messages framework https://docs.djangoproject.com/en/dev/ref/contrib/messages/

to manipulate existing messages:

storage = messages.get_messages(request)
for message in storage:
    do_something_with(message)

to add new message:

messages.add_message(request, messages.INFO, 'An info.')
messages.add_message(request, messages.SUCCESS, 'An success.')

To use this code, you will have to either override django admin views or create a middleware that will handle these messages. See this for overriding admin views: https://docs.djangoproject.com/en/1.4/ref/contrib/admin/#django.contrib.admin.ModelAdmin.change_view

Upvotes: 1

Related Questions