views:

19

answers:

1

I've written custom admin actions that basically do QuerySet.update() for certain fields in the model. There are times when these actions shouldn't be allowed to complete -- instead, they should display an error and not do anything. I've tried message_user, but that displays a green checkmark, whereas I'd like it to display the Django admin error message.

A solution I've found online is to use a ModelForm, but I don't think that applies in this case, as here everything happens on the admin change list page.

A: 

The message_user function used within the admin simply uses the contrib.messages package. You could try something like this:

from django.contrib import messages

# Then, when you need to error the user:
messages.error(request, "The message")

You can also use warning, debug, info and success in place of error

Hope that helps!

Bartek