Opened 3 weeks ago

Last modified 12 days ago

#37399 assigned Cleanup/optimization

Include module_name in all model admin views with breadcrumbs

Reported by: Marijke Luttekes Owned by: Denny Biasiolli
Component: contrib.admin Version: dev
Severity: Normal Keywords:
Cc: Marijke Luttekes Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

Provide a context variable module_name to all model admin views that do not yet have this value, for consistency.

This value is a capitalized version of a model's pluralized verbose name, typically used in the third breadcrumb link that points to a changelist view.

Reasoning

As originally mentioned on the forum: ​Some potential bugs found when making custom admin pages.

Some model admin pages like the history view (template: ​object_history.html) provide a context variable module_name, which is used in the breadcrumbs block of the template.

Other templates, e.g., the add/edit view (template: ​change_form.html) do not provide this value as context data. Instead, they modify the object's verbose plural name in place within the breadcrumbs block.

Adding this value to all the relevant admin templates would make the code more consistent.

Python code

This is is how we build the module name in Python from a ModelAdmin instance:

opts = self.model._meta
module_name = str(capfirst(opts.verbose_name_plural))

Templates like change_form.html use this code instead:

{{ opts.verbose_name_plural|capfirst }}

Change History (8)

comment:1 by Vaibhav Pant, 3 weeks ago

Owner: set to Vaibhav Pant
Status: new → assigned

comment:2 by Marijke Luttekes, 3 weeks ago

Owner: Vaibhav Pant removed
Status: assigned → new

I'm unassigning Vaibhav Pant because I was waiting for this ticket to be triaged before picking it up myself.

Please do not assign a ticket to yourself within a minute of its creation without discussion.

If, after triage, I'm unable to pick it up, I'll make a post here.

comment:3 by Denny Biasiolli, 3 weeks ago

Hey Marijke, since this morning I was trying to analyze this same issue after looking at the notes I took during your talk on Friday.
I started playing with the code, then, before opening a ticket I tried to search for something similar, and guess what? I just noticed this ticket from you, just from 1 hour ago! :)

I'm happy to help with this if needed, parking my branch on my GitHub here (​https://github.com/dennybiasiolli/django/tree/ticket_37399) in case you want to have a look at that

comment:4 by Prakhar Goyal, 3 weeks ago

Owner: set to Prakhar Goyal
Status: new → assigned

comment:5 by Marijke Luttekes, 3 weeks ago

Owner: changed from Prakhar Goyal to Marijke Luttekes

Assigning to myself to prevent others from taking this issue.

Denny and I have been looking at this behind the scenes, and he will have a PR ready after triage.

comment:6 by Sarah Boyce, 2 weeks ago

Triage Stage: Unreviewed → Accepted

Thank you for the ticket
Happy to see greater consistency in the admin, look forward to seeing the patch

comment:7 by Denny Biasiolli, 12 days ago

Has patch: set

comment:8 by Marijke Luttekes, 12 days ago

Cc: Marijke Luttekes added
Owner: changed from Marijke Luttekes to Denny Biasiolli

Assigned to Denny since the PR is in his name.

Note: See TracTickets for help on using tickets.
Back to Top