Hello everyone,
I’m working on PR #20903, which addresses a long-standing ticket (#10919) regarding the delete confirmation page in contrib.admin.
Currently, when deleting an object with many children, the recursive list of related objects can become massive (see example on ticket). This pushes the “Yes, I’m sure” button far out of view and can lead to extremely large HTML payloads that degrade the browser experience and accessibility.
The proposed solution in the PR adds a new attributeModelAdmin.delete_confirmation_max_display, to cap the visual list, i.e show the first 100 items and then “…and N more”. The default value is None, which makes this attribute/feature opt-in.
This is how the change looks like if we set the value to 2 (probably users would pick a higher number, but I just want to keep the screenshot short)
This is a frontend-only optimization, we’re not limiting the database query. One of the main reasons is that we need to traverse the whole recursive tree to collect the counters of all nested objects anyway, to show the summary on the top of the page, it’s the same set of queries.
One of the decisions we’ve been going back and forth on the PR is whether we should cap the items per nesting level or globally, and I wonder if we can get to a consensus here.
Truncating per nesting level is like the screenshot above; for example, if I set a limit of 10, I would expect to see 10 children at most, and then 10 grandchildren for each, and so on. The rationale is that I’d rather see 10 posts than 1 post and 9 comments, to have a better sense of what’s being deleted, it maximizes visibility of the items affected.
One downside is that if we have mixed types on the same level like
Foo:
Bar:
Baz:
…and 2 more
..it may look like there are 2 more “Baz” which is not necessarily true, it could be anything.
OTOH If we truncate globally, we could have a message like “…and N more objects” only once, at the end of the list, and have a more predictable page size, like the screenshot linked next. In this case the limit was set to 10, so it shows 1 blog, 1 post and 8 comments (total 10) - you can see an example here.
Do you have any preferences? see a better alternative?
Please let me know if anything is unclear. Thanks @jacobtylerwalls for the great suggestions and guidance on this PR, it’s my first
Cheers!
