diff --git a/django/django/contrib/admin/actions.py b/django/django/contrib/admin/actions.py
index 86edb0a..29fe28c 100644
a
|
b
|
def delete_selected(modeladmin, request, queryset):
|
51 | 51 | if request.POST.get('post'): |
52 | 52 | if perms_needed: |
53 | 53 | raise PermissionDenied |
54 | | n = queryset.count() |
55 | | if n: |
56 | | for obj in queryset: |
57 | | obj_display = force_unicode(obj) |
| 54 | |
| 55 | n = 0 |
| 56 | for obj in queryset: |
| 57 | obj_display = force_unicode(obj) |
| 58 | if modeladmin.delete_model(request, obj): |
58 | 59 | modeladmin.log_deletion(request, obj, obj_display) |
59 | | queryset.delete() |
| 60 | n += 1 |
| 61 | |
| 62 | if n > 0: |
60 | 63 | modeladmin.message_user(request, _("Successfully deleted %(count)d %(items)s.") % { |
61 | 64 | "count": n, "items": model_ngettext(modeladmin.opts, n) |
62 | 65 | }) |
| 66 | |
63 | 67 | # Return None to display the change list page again. |
64 | 68 | return None |
65 | 69 | |
diff --git a/django/django/contrib/admin/options.py b/django/django/contrib/admin/options.py
index d83b4aa..4638f7e 100644
a
|
b
|
class ModelAdmin(BaseModelAdmin):
|
554 | 554 | |
555 | 555 | def save_model(self, request, obj, form, change): |
556 | 556 | """ |
557 | | Given a model instance save it to the database. |
| 557 | Given a model instance save it to the database. Returns True to |
| 558 | indicate that the instance was saved successful. Derived classes can |
| 559 | override this method an let it return False to indicate, that the |
| 560 | instance was not saved for some reasons. You must call message_user() |
| 561 | yourself, to notify the user about the failure and its reason, if you |
| 562 | return False. |
558 | 563 | """ |
559 | 564 | obj.save() |
| 565 | return True |
| 566 | |
| 567 | def delete_model(self, request, obj): |
| 568 | """ |
| 569 | Given a model instance delete it from the database. Returns True to |
| 570 | indicate that the instance was saved successful. Derived classes can |
| 571 | override this method an let it return False to indicate, that the |
| 572 | instance was not deleted for some reasons. You must call message_user() |
| 573 | yourself, to notify the user about the failure and its reason, if you |
| 574 | return False. |
| 575 | """ |
| 576 | obj.delete() |
| 577 | return True |
560 | 578 | |
561 | 579 | def save_formset(self, request, form, formset, change): |
562 | 580 | """ |
… |
… |
class ModelAdmin(BaseModelAdmin):
|
733 | 751 | save_as_new=request.POST.has_key("_saveasnew"), |
734 | 752 | prefix=prefix) |
735 | 753 | formsets.append(formset) |
736 | | if all_valid(formsets) and form_validated: |
737 | | self.save_model(request, new_object, form, change=False) |
| 754 | if all_valid(formsets) and form_validated and self.save_model(request, new_object, form, change=False): |
738 | 755 | form.save_m2m() |
739 | 756 | for formset in formsets: |
740 | 757 | self.save_formset(request, form, formset, change=False) |
… |
… |
class ModelAdmin(BaseModelAdmin):
|
829 | 846 | instance=new_object, prefix=prefix) |
830 | 847 | formsets.append(formset) |
831 | 848 | |
832 | | if all_valid(formsets) and form_validated: |
833 | | self.save_model(request, new_object, form, change=True) |
| 849 | if all_valid(formsets) and form_validated and self.save_model(request, new_object, form, change=True): |
834 | 850 | form.save_m2m() |
835 | 851 | for formset in formsets: |
836 | 852 | self.save_formset(request, form, formset, change=True) |
… |
… |
class ModelAdmin(BaseModelAdmin):
|
930 | 946 | for form in formset.forms: |
931 | 947 | if form.has_changed(): |
932 | 948 | obj = self.save_form(request, form, change=True) |
933 | | self.save_model(request, obj, form, change=True) |
934 | | form.save_m2m() |
935 | | change_msg = self.construct_change_message(request, form, None) |
936 | | self.log_change(request, obj, change_msg) |
937 | | changecount += 1 |
| 949 | if self.save_model(request, obj, form, change=True): |
| 950 | form.save_m2m() |
| 951 | change_msg = self.construct_change_message(request, form, None) |
| 952 | self.log_change(request, obj, change_msg) |
| 953 | changecount += 1 |
938 | 954 | |
939 | 955 | if changecount: |
940 | 956 | if changecount == 1: |
… |
… |
class ModelAdmin(BaseModelAdmin):
|
1017 | 1033 | if perms_needed: |
1018 | 1034 | raise PermissionDenied |
1019 | 1035 | obj_display = force_unicode(obj) |
1020 | | self.log_deletion(request, obj, obj_display) |
1021 | | obj.delete() |
1022 | 1036 | |
1023 | | self.message_user(request, _('The %(name)s "%(obj)s" was deleted successfully.') % {'name': force_unicode(opts.verbose_name), 'obj': force_unicode(obj_display)}) |
| 1037 | if self.delete_model(request, obj): |
| 1038 | self.log_deletion(request, obj, obj_display) |
| 1039 | self.message_user(request, _('The %(name)s "%(obj)s" was deleted successfully.') % {'name': force_unicode(opts.verbose_name), 'obj': obj_display}) |
| 1040 | elif self.has_change_permission(request, obj): |
| 1041 | return HttpResponseRedirect("../") |
1024 | 1042 | |
1025 | 1043 | if not self.has_change_permission(request, None): |
1026 | 1044 | return HttpResponseRedirect("../../../../") |