diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py index 7b3018e819..e73ea8f388 100644 --- a/django/contrib/admin/options.py +++ b/django/contrib/admin/options.py @@ -1012,9 +1012,9 @@ class ModelAdmin(BaseModelAdmin): if perms_needed: raise PermissionDenied obj_display = force_unicode(obj) + self.log_deletion(request, obj, obj_display) obj.delete() - self.log_deletion(request, obj, obj_display) self.message_user(request, _('The %(name)s "%(obj)s" was deleted successfully.') % {'name': force_unicode(opts.verbose_name), 'obj': force_unicode(obj_display)}) if not self.has_change_permission(request, None): diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py index a571995d45..774f79f1b1 100644 --- a/tests/regressiontests/admin_views/tests.py +++ b/tests/regressiontests/admin_views/tests.py @@ -6,7 +6,7 @@ from django.core.files import temp as tempfile from django.test import TestCase from django.contrib.auth.models import User, Permission from django.contrib.contenttypes.models import ContentType -from django.contrib.admin.models import LogEntry +from django.contrib.admin.models import LogEntry, DELETION from django.contrib.admin.sites import LOGIN_FORM_KEY from django.contrib.admin.util import quote from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME @@ -544,6 +544,9 @@ class AdminViewPermissionsTest(TestCase): post = self.client.post('/test_admin/admin/admin_views/article/1/delete/', delete_dict) self.assertRedirects(post, '/test_admin/admin/') self.failUnlessEqual(Article.objects.all().count(), 2) + article_ct = ContentType.objects.get_for_model(Article) + logged = LogEntry.objects.get(content_type=article_ct, action_flag=DELETION) + self.failUnlessEqual(logged.object_id, u'1') self.client.get('/test_admin/admin/logout/') class AdminViewStringPrimaryKeyTest(TestCase):