Breadcrumbs in custom admin view (Django)

Viewed 2636

I have custom admin view which works fine, except that I would like to add breadcrumbs.

Up to now I only see "Start". But I would like to see "Start > Foo".

django-admin-breadcrumbs

What do I need to add to my template?

2 Answers

Unfortunately (AFAIK) you can't extend the breadcrumbs, you can only overwrite the whole breadcrumbs "line".

Just provide the block "breadcrumbs" and use the appropriate css class for the div:

{% extends 'admin/base_site.html' %}
{% load i18n %}

{% block breadcrumbs %}
<div class="breadcrumbs">
  <a href="{% url 'admin:index' %}">{% trans 'Home' %}</a>
  &rsaquo; <a href="...">Foo</a>
</div>
{% endblock %}

{% block content %}
 ....

If someone know a way to extend the breadcrumbs (just add "Foo", without providing a link for "admin:index"), then please leave a comment!

I don't think it can be done via the template without overriding the whole breadcrumbs block, but in your view method you can add a title key to the context passed to the template

    def my_view(self, request):
        # ...
        context = dict(
           # Include common variables for rendering the admin template.
           self.admin_site.each_context(request),
           # Anything else you want in the context...
           title="Foo",
        )
        return TemplateResponse(request, "sometemplate.html", context)
Related