Ticket #11296: django_delete_objects_in_admin.diff

File django_delete_objects_in_admin.diff, 2.2 KB (added by Ben, 10 years ago)

A patch.

  • django/contrib/admin/util.py

     
    7171    except NoReverseMatch:
    7272        return '%s%s/%s/%s/' % ('../'*levels_to_root, app_label, module_name, pk)
    7373
    74 def get_deleted_objects(deleted_objects, perms_needed, user, obj, opts, current_depth, admin_site, levels_to_root=4):
     74def get_deleted_objects(deleted_objects, perms_needed, user, obj, opts, current_depth, admin_site, levels_to_root=4, opts_seen=[]):
    7575    """
    7676    Helper function that recursively populates deleted_objects.
    7777
     
    8585    nh = _nest_help # Bind to local variable for performance
    8686    if current_depth > 16:
    8787        return # Avoid recursing too deep.
    88     opts_seen = []
    8988    for related in opts.get_all_related_objects():
    9089        has_admin = related.model in admin_site._registry
    9190        if related.opts in opts_seen:
     
    119118                                            admin_site,
    120119                                            levels_to_root),
    121120                        escape(sub_obj))), []])
    122                 get_deleted_objects(deleted_objects, perms_needed, user, sub_obj, related.opts, current_depth+2, admin_site)
     121                get_deleted_objects(deleted_objects, perms_needed, user, sub_obj, related.opts, current_depth+2, admin_site, opts_seen=opts_seen)
    123122        else:
    124123            has_related_objs = False
    125124            for sub_obj in getattr(obj, rel_opts_name).all():
     
    139138                                            admin_site,
    140139                                            levels_to_root),
    141140                        escape(sub_obj))), []])
    142                 get_deleted_objects(deleted_objects, perms_needed, user, sub_obj, related.opts, current_depth+2, admin_site)
     141                get_deleted_objects(deleted_objects, perms_needed, user, sub_obj, related.opts, current_depth+2, admin_site, opts_seen=opts_seen)
    143142            # If there were related objects, and the user doesn't have
    144143            # permission to delete them, add the missing perm to perms_needed.
    145144            if has_admin and has_related_objs:
Back to Top