Opened 13 years ago

Closed 13 years ago

Last modified 12 years ago

#162 closed defect (fixed)

admin log accesses __repr__ too late (w/patch)

Reported by: mfenniak@… Owned by: Adrian Holovaty
Component: contrib.admin Version:
Severity: minor Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


If a meta.Model class has a repr function like this:

    def __repr__(self):
        return "Object #%s" % (,)

When the object is deleted through the administration interface, the user interface shows that: The object "Object #None" was deleted successfully. A similar message appears in the admin log. It would suggest that the object's representation should be cached before it is deleted for display in the UI and logs.

This quick and simple patch fixes the problem:

Index: django/views/admin/
--- django/views/admin/  (revision 293)
+++ django/views/admin/  (working copy)
@@ -1056,8 +1059,8 @@
     if request.POST: # The user has already confirmed the deletion.
         if perms_needed:
             raise PermissionDenied
+        obj_repr = repr(obj)
-        obj_repr = repr(obj)
         log.log_action(, opts.get_content_type_id(), object_id, obj_repr, log.DELETION)
         request.user.add_message('The %s "%s" was deleted successfully.' % (opts.verbose_name, obj_repr))
         return HttpResponseRedirect("../../")

Change History (1)

comment:1 Changed 13 years ago by Adrian Holovaty

Resolution: fixed
Status: newclosed

(In [324]) Fixed #162 -- Admin log now records repr() before calling delete(), instead of after calling it() -- thanks, mfenniak@…!

Note: See TracTickets for help on using tickets.
Back to Top