Better support for exceptions / error messages in custom admin actions
|Reported by:||dbrgn||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_user method 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.
Change History (9)
comment:1 Changed 20 months ago by tswicegood
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Triage Stage changed from Unreviewed to Accepted
comment:2 Changed 20 months ago by tswicegood
- Type changed from Uncategorized to Cleanup/optimization
comment:8 Changed 17 months ago by Preston Holmes <preston@…>
- Resolution set to fixed
- Status changed from new to closed