Skip to content

Add block for home in admin breadcrumbs #86

@jaredahern

Description

@jaredahern

Code of Conduct

  • I agree to follow Django's Code of Conduct

Feature Description

The "Home" link is repeated in the breadcrumbs block of many admin templates. There are sometimes other links that are repeated as well. I propose that the "Home" link (at least) be wrapped in a block and reused.

Problem

One advantage is that it would be better from a DRY perspective. Another reason is something that I have needed to do: change breadcrumbs such that the site root URL is shown in the breadcrumbs as "Home" and the admin index page (the usual "Home" link) is shown as a link in the breadcrumbs after "Home". At present, this involves overriding the breadcrumbs block in every admin template. It would be much better if this could be changed in a single place.

Request or proposal

proposal

Additional Details

I came across the work being done in django/django#19492 to support https://code.djangoproject.com/ticket/34041 . The work there looks great - I hope it gets wrapped up and merged. After reading through the changes, I thought that this idea was sufficiently different to warrant a separate issue.

My thought is that this is a minimal change that should be backwards compatible. Given that the breadcrumbs would change with the aforementioned PR, perhaps it would be best to release these changes together. This change could be added there, or added in a PR shortly after for the same Django release.

Happy to help on a PR, if that should be separate from PR 19492. Please let me know what you think!

Implementation Suggestions

Examples here are based on PR 19492 . In base.html, do this:

{% block breadcrumbs %}
<ol class="breadcrumbs">
{% block breadcrumb-root %}
<li><a href="{% url 'admin:index' %}">{% translate 'Home' %}</a></li>
{% endblock %}
{% if title %}<li><a href="" aria-current="page">{{ title }}</a></li>{% endif %}
</ol>
{% endblock %}

For other templates (e.g. change_list.html here), call super:

{% block breadcrumbs %}
<ol class="breadcrumbs">
{% block breadcrumb-root %}{{ block.super }}{% endblock %}
<li><a href="{% url 'admin:app_list' app_label=cl.opts.app_label %}">{{ cl.opts.app_config.verbose_name }}</a></li>
<li><a href="" aria-current="page">{{ cl.opts.verbose_name_plural|capfirst }}</a></li>
</ol>
{% endblock %}

With this approach, I believe that the home link can be changed once, e.g. in base_site.html, and impact all admin pages. Additional child page links could also be appended to the breadcrumb-root block for any templates where it makes sense to inherit them in a child template.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Idea

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions