Skip to main content

Django generic view breadcrumbs

Project description

django-view-breadcrumbs Build Status Codacy Badge PyPI version

This extends django-bootstrap-breadcrumbs providing generic breadcrumb mixin classes.

This will replace having to add {% breadcrumb $label $viewname [*args] [**kwargs] %} to every template.

Breadcrumb mixin classes provided.

  • BaseBreadcrumbMixin - Base view requires a crumbs class property.
  • CreateBreadcrumbMixin - For create views Home \ Posts \ Add Post
  • DetailBreadcrumbMixin - For detail views Home \ Posts \ Post 1
  • ListBreadcrumbMixin - For list views Home \ Posts
  • UpdateBreadcrumbMixin - For Update views Home \ Posts \ Post 1 \ Update Post 1

Installation:

$ pip install django-view-breadcrumbs

Add app to your INSTALLED_APPS

INSTALLED_APPS = [
    ...
    'view-breadcrumbs',
    ...
]

Usage:

django-view-breadcrumbs includes generic mixins that can be added to a class based view.

Using the generic breadcrumb mixin each breadcrumb will added for each view dynamically using the view model class and can be overridden by providing a crumbs property.

Sample crumbs: Home \ Posts \ Test - Post

from django.views.generic import DetailView
from django_view_breadcrumbs import DetailBreadcrumbMixin


class PostDetail(DetailBreadcrumbMixin, DetailView):
    model = Post
    template_name = 'app/post/detail.html'

In your base.html template simply add the render_breadcrumbs tag and any template that inherits the base should have breadcrumbs included.

{% load django_bootstrap_breadcrumbs %}

{% block breadcrumbs %}
    {% render_breadcrumbs %}
{% endblock %}

All crumbs use the home root path \ as the base this can be excluded by specifying add_home = False

Sample crumbs: Posts

from django.views.generic import ListView
from django_view_breadcrumbs import ListBreadcrumbMixin


class PostList(ListBreadcrumbMixin, ListView):
    model = Post
    template_name = 'app/post/list.html'
    add_home = False

Can also override the view breadcrumb by specifying a list of tuples [(Label, view path)].

Custom crumbs: Home \ My Test Breadcrumb

URL conf.

urlpatterns = [
   path('my-test-list-view/', views.TestView.as_view(), name='test_list_view'),
   path('my-test-detail-view/<int:pk>/', views.TestView.as_view(), name='test_detail_view'),
]

views.py

from django.urls import reverse
from django.views.generic import ListView
from django_view_breadcrumbs import ListBreadcrumbMixin


class TestView(ListBreadcrumbMixin, ListView):
    model = TestModel
    template_name = 'app/test/test-list.html'
    crumbs = [('My Test Breadcrumb', reverse('test_list_view')]

OR

class TestView(ListBreadcrumbMixin, ListView):
    model = TestModel
    template_name = 'app/test/test-list.html'

    @cached_property
    def crumbs(self):
        return super(TestView, self).crumbs + [
            (self.object.name , reverse('test_detail_view', kwargs={'pk': self.object.pk})
        ]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-view-breadcrumbs-0.0.3.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

django_view_breadcrumbs-0.0.3-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file django-view-breadcrumbs-0.0.3.tar.gz.

File metadata

  • Download URL: django-view-breadcrumbs-0.0.3.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.1.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.4

File hashes

Hashes for django-view-breadcrumbs-0.0.3.tar.gz
Algorithm Hash digest
SHA256 3e8bc3ab7b99977b1c3d5427e1cfb582c891c5d8ab988ba3f2c07ac5b25f73ff
MD5 a952bfa7af7b02c9d42551cc4817a850
BLAKE2b-256 f0d5df04000e5ae1a02d1d7d29bb39cdf3edcc70723e82b65215987bd2bf5421

See more details on using hashes here.

File details

Details for the file django_view_breadcrumbs-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: django_view_breadcrumbs-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.1.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.4

File hashes

Hashes for django_view_breadcrumbs-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d65c0c6b8c64ae1698ea6610cf1a0d0a2be949aaac0e1e717adf94b5d0538f3c
MD5 e161981830f1fc91c5c67f4a7e787b49
BLAKE2b-256 a2882a439772a7e7d39d98e364906c43a597ec5c53d98d45736474ca7d03b877

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page