#33868 closed Cleanup/optimization (wontfix)
Admin “delete object(s)” view: improve labels of m2m relations
| Reported by: | julian@pinabausch.org | Owned by: | nobody | 
|---|---|---|---|
| Component: | contrib.admin | Version: | 4.0 | 
| Severity: | Normal | Keywords: | admin, delete view | 
| Cc: | julian@pinabausch.org, Adam Johnson | Triage Stage: | Unreviewed | 
| Has patch: | yes | Needs documentation: | no | 
| Needs tests: | yes | Patch needs improvement: | no | 
| Easy pickings: | no | UI/UX: | no | 
Description (last modified by )
When deleting an object that has m2m relations in Django Admin, it shows a nice overview of what’s going to be deleted, including the records from m2m relations. An example screenshot is attached to the ticket.
The labels for the m2m relations are constructed like this:
Photo-person relationship: Photo_depicts object (1)
Photo-person relationship makes perfect sense to me; Photo_depicts object (1) could be improved.
I suggest using the labels of the string representation of the concrete from- and to-objects.
Let me know what you think about it and I will see if I can come up with a patch.
Update:
Here’s a possible fix: https://github.com/django/django/pull/15884
Some remarks:
- The 
fromandtomodels should be fetched withselect_relatedbefore__str__is called - This is not a change to django admin (as planned), but it affects *all* auto-generated m2m models . What are the ceveats?
 - Translations are missing currently
 - I'm happy to provide tests if this goes in the right direction
 
Background:
Two years ago, I had a discussion on the Django developers mailing list about improving the labels that are used for m2m relations in Django Admin’s delete view. While reviewing old tickets to day, I checked the mailing list again and thought “Why not give it another shot?”.
https://groups.google.com/g/django-developers/c/TxZtZyB3kpc
Attachments (2)
Change History (9)
by , 3 years ago
| Attachment: | Bildschirmfoto 2022-07-26 um 13.48.32.png added | 
|---|
comment:1 by , 3 years ago
| Cc: | added | 
|---|---|
| Description: | modified (diff) | 
comment:2 by , 3 years ago
| Description: | modified (diff) | 
|---|
comment:3 by , 3 years ago
| Has patch: | set | 
|---|---|
| Needs tests: | set | 
by , 3 years ago
| Attachment: | Bildschirmfoto 2022-07-26 um 22.28.39.png added | 
|---|
Sample delete view with improved labels
comment:4 by , 3 years ago
| Description: | modified (diff) | 
|---|
comment:5 by , 3 years ago
| Cc: | added | 
|---|---|
| Triage Stage: | Unreviewed → Accepted | 
OK, thanks Julian — let's take this for review, since the discussion with Adam was broadly positive (pending any possible blockers). 
comment:6 by , 3 years ago
| Resolution: | → wontfix | 
|---|---|
| Status: | new → closed | 
Closing this – the improved labels can only be implemented by fetching the “from” and “to” instances from the database, i.e. introducing a performance regression. The current implementation’s labels are created based on the models’ verbose names and the m2m instance’s ID, which is quite performance-friendly.
comment:7 by , 3 years ago
| Triage Stage: | Accepted → Unreviewed | 
|---|
Closing as "wonfix" due to backward compatibility concerns and a possible performance regression. Users can always override __str__ in their app, e.g.
class FirstModel(models.Model): pass class SecondModel(models.Model): firsts = models.ManyToManyField(FirstModel) def to_str(self): return f"between {self.firstmodel} and {self.secondmodel}" SecondModel.firsts.through.__str__ = to_str
Delete view sample – deleting a Photo instance that has a “depcits” relation to four people