Better support for exceptions / error messages in custom admin actions
|Reported by:||Danilo Bargen||Owned by:||thiderman|
|Severity:||Normal||Keywords:||admin, exception handling, ui/ux, docs|
|Cc:||Triage Stage:||Ready for checkin|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
The docs don't mention any way to create error messages in custom admin actions. According to an answer on Stackoverflow, this can be achieved with:
from django.contrib import messages # Then, when you need to error the user: messages.error(request, "The message")
There are three issues with this:
- There's a
message_usermethod on a ModelAdmin, but no similar thing for errors. This seems inconsistent.
- It's not mentioned in the docs. Errors in actions need to be handled.
- The error message isn't rendered with red background color, as it should be. A possible fix is described here.