Opened 63 minutes ago
Last modified 7 minutes ago
#37399 new Cleanup/optimization
Include module_name in all model admin views with breadcrumbs
| Reported by: | Marijke Luttekes | Owned by: | |
|---|---|---|---|
| Component: | contrib.admin | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | 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 (2)
comment:1 by , 62 minutes ago
| Owner: | set to |
|---|---|
| Status: | new → assigned |
comment:2 by , 7 minutes ago
| Owner: | 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.