Ticket #11296: django_delete_objects_in_admin_2.diff
File django_delete_objects_in_admin_2.diff, 2.2 KB (added by , 15 years ago) |
---|
-
django/contrib/admin/util.py
71 71 except NoReverseMatch: 72 72 return '%s%s/%s/%s/' % ('../'*levels_to_root, app_label, module_name, pk) 73 73 74 def get_deleted_objects(deleted_objects, perms_needed, user, obj, opts, current_depth, admin_site, levels_to_root=4 ):74 def get_deleted_objects(deleted_objects, perms_needed, user, obj, opts, current_depth, admin_site, levels_to_root=4, opts_seen=[]): 75 75 """ 76 76 Helper function that recursively populates deleted_objects. 77 77 … … 85 85 nh = _nest_help # Bind to local variable for performance 86 86 if current_depth > 16: 87 87 return # Avoid recursing too deep. 88 opts_seen = []88 opts_seen += [obj._meta] 89 89 for related in opts.get_all_related_objects(): 90 90 has_admin = related.model in admin_site._registry 91 91 if related.opts in opts_seen: … … 119 119 admin_site, 120 120 levels_to_root), 121 121 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) 123 123 else: 124 124 has_related_objs = False 125 125 for sub_obj in getattr(obj, rel_opts_name).all(): … … 139 139 admin_site, 140 140 levels_to_root), 141 141 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) 143 143 # If there were related objects, and the user doesn't have 144 144 # permission to delete them, add the missing perm to perms_needed. 145 145 if has_admin and has_related_objs: