Code

Ticket #10889: admin-log-deletion.diff

File admin-log-deletion.diff, 2.3 KB (added by 3point2, 4 years ago)
Line 
1Index: django/contrib/admin/options.py
2===================================================================
3--- django/contrib/admin/options.py     (revision 13975)
4+++ django/contrib/admin/options.py     (working copy)
5@@ -445,11 +445,11 @@
6             change_message  = message
7         )
8 
9-    def log_deletion(self, request, object, object_repr):
10+    def log_deletion(self, request, object_pk, object_repr):
11         """
12         Log that an object has been successfully deleted. Note that since the
13         object is deleted, it might no longer be safe to call *any* methods
14-        on the object, hence this method getting object_repr.
15+        on the object, hence this method getting object_repr and object_pk.
16 
17         The default implementation creates an admin LogEntry object.
18         """
19@@ -457,7 +457,7 @@
20         LogEntry.objects.log_action(
21             user_id         = request.user.id,
22             content_type_id = ContentType.objects.get_for_model(self.model).pk,
23-            object_id       = object.pk,
24+            object_id       = object_pk,
25             object_repr     = object_repr,
26             action_flag     = DELETION
27         )
28@@ -1112,8 +1116,9 @@
29             if perms_needed:
30                 raise PermissionDenied
31             obj_display = force_unicode(obj)
32-            self.log_deletion(request, obj, obj_display)
33+            obj_pk = obj.pk
34             obj.delete()
35+            self.log_deletion(request, obj_pk, obj_display)
36 
37             self.message_user(request, _('The %(name)s "%(obj)s" was deleted successfully.') % {'name': force_unicode(opts.verbose_name), 'obj': force_unicode(obj_display)})
38 
39Index: django/contrib/admin/actions.py
40===================================================================
41--- django/contrib/admin/actions.py     (revision 13975)
42+++ django/contrib/admin/actions.py     (working copy)
43@@ -43,7 +43,7 @@
44         if n:
45             for obj in queryset:
46                 obj_display = force_unicode(obj)
47-                modeladmin.log_deletion(request, obj, obj_display)
48+                modeladmin.log_deletion(request, obj.pk, 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)