#18658 closed Cleanup/optimization (fixed)
Better support for exceptions / error messages in custom admin actions
Reported by: | Danilo Bargen | Owned by: | thiderman |
---|---|---|---|
Component: | contrib.admin | Version: | 1.4 |
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 |
Easy pickings: | yes | UI/UX: | no |
Description
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 by , 12 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 12 years ago
Type: | Uncategorized → Cleanup/optimization |
---|
comment:3 by , 12 years ago
Owner: | changed from | to
---|
I'll tackle this one as part of my work at the Django sprint in Stockholm!
comment:4 by , 12 years ago
Has patch: | set |
---|
Added pull request: https://github.com/django/django/pull/529
comment:5 by , 12 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:6 by , 12 years ago
Allowing a string for the level for convenience seems fine - but we should still accept messages.INFO style constants.
I've made that change and added some more docs and release note here:
Thanks for your work on this
comment:8 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Thanks. Definitely something we should add. Probably something along the lines of adding a
level
kwarg tomessage_user
.