diff --git a/django/contrib/admin/actions.py b/django/contrib/admin/actions.py
index d215aa6..93c91df 100644
a
|
b
|
from django.db import router
|
10 | 10 | from django.template.response import TemplateResponse |
11 | 11 | from django.utils.encoding import force_text |
12 | 12 | from django.utils.translation import ugettext_lazy, ugettext as _ |
| 13 | from django.db.models.deletion import ProtectedError |
13 | 14 | |
14 | 15 | |
15 | 16 | def delete_selected(modeladmin, request, queryset): |
… |
… |
def delete_selected(modeladmin, request, queryset):
|
46 | 47 | for obj in queryset: |
47 | 48 | obj_display = force_text(obj) |
48 | 49 | modeladmin.log_deletion(request, obj, obj_display) |
49 | | queryset.delete() |
50 | | modeladmin.message_user(request, _("Successfully deleted %(count)d %(items)s.") % { |
51 | | "count": n, "items": model_ngettext(modeladmin.opts, n) |
52 | | }, messages.SUCCESS) |
| 50 | try: |
| 51 | queryset.delete() |
| 52 | modeladmin.message_user(request, _("Successfully deleted %(count)d %(items)s.") % { |
| 53 | "count": n, "items": model_ngettext(modeladmin.opts, n) |
| 54 | }, messages.SUCCESS) |
| 55 | except ProtectedError, e: |
| 56 | modeladmin.message_user(request, _("Could not delete %(items)s: %(msg)s.") % { |
| 57 | "items": model_ngettext(modeladmin.opts, n), "msg": e.args[0] |
| 58 | }, messages.ERROR) |
| 59 | |
53 | 60 | # Return None to display the change list page again. |
54 | 61 | return None |
55 | 62 | |