Ticket #11296: django_delete_objects_in_admin_2.diff

File django_delete_objects_in_admin_2.diff, 2.2 KB (added by Ben Davis, 9 years ago)

Updated to not recurse through object being deleted

  • 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 = []
     88    opts_seen += [obj._meta]
    8989    for related in opts.get_all_related_objects():
    9090        has_admin = related.model in admin_site._registry
    9191        if related.opts in opts_seen:
     
    119119                                            admin_site,
    120120                                            levels_to_root),
    121121                        escape(sub_obj))), []])
    122                 get_deleted_objects(deleted_objects, perms_needed, user, sub_obj, related.opts, current_depth+2, admin_site)
     122                get_deleted_objects(deleted_objects, perms_needed, user, sub_obj, related.opts, current_depth+2, admin_site, opts_seen=opts_seen)
    123123        else:
    124124            has_related_objs = False
    125125            for sub_obj in getattr(obj, rel_opts_name).all():
     
    139139                                            admin_site,
    140140                                            levels_to_root),
    141141                        escape(sub_obj))), []])
    142                 get_deleted_objects(deleted_objects, perms_needed, user, sub_obj, related.opts, current_depth+2, admin_site)
     142                get_deleted_objects(deleted_objects, perms_needed, user, sub_obj, related.opts, current_depth+2, admin_site, opts_seen=opts_seen)
    143143            # If there were related objects, and the user doesn't have
    144144            # permission to delete them, add the missing perm to perms_needed.
    145145            if has_admin and has_related_objs:
Back to Top