Django generic view breadcrumbs
Project description
django-view-breadcrumbs
This extends django-bootstrap-breadcrumbs providing generic breadcrumb mixin classes.
Replaces having to add {% breadcrumb $label $viewname [*args] [**kwargs] %}
to every template.
Breadcrumb mixin classes provided.
BaseBreadcrumbMixin
- Base view requires acrumbs
class property.CreateBreadcrumbMixin
- For create viewsHome \ Posts \ Add Post
DetailBreadcrumbMixin
- For detail viewsHome \ Posts \ Post 1
ListBreadcrumbMixin
- For list viewsHome \ Posts
UpdateBreadcrumbMixin
- For Update viewsHome \ 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 be added to the view dynamically
and can be overridden by providing a crumbs
property.
Sample crumbs: Home \ Posts \ Test - Post
NOTE: All url config should use a pattern
view_name=model_verbose_name_{action}
i.eview_name=post_detail
for detail view.
Actions include:
- "list" -
ListView
- "change" -
UpdateView
- "detail" -
DetailView
In your urls.py
urlpatterns = [
...
path('posts/<slug:slug>', views.PostDetail.as_view(), name='post_detail'),
...
]
views.py
from django.views.generic import DetailView
from 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.
i.e
In your base.html
{% load django_bootstrap_breadcrumbs %}
{% block breadcrumbs %}
{% render_breadcrumbs %}
{% endblock %}
And your create.html
.
{% extends 'base.html' %}
All crumbs use the home root path
\
as the base this can be excluded by specifyingadd_home = False
Sample crumbs: Posts
from django.views.generic import ListView
from 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 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 reverse_lazy
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django-view-breadcrumbs-0.0.5.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 832a8735751d5a10fe6b8cd13bf66a29082e58bad5c3ebf065eb5cbf6a388efb |
|
MD5 | 12ff611a392587c64d0e3cc5f7af12fe |
|
BLAKE2b-256 | 32c8005f3cd4e6b4f8113dc956f5e7e002aeec6403c7fa89dc409a4620444002 |
Hashes for django_view_breadcrumbs-0.0.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c62348b6e69af180bc00dfd53b6c2d4a619277b7b653404b795fe8c72f2f727e |
|
MD5 | 491eed36a061f966496a51d848e258e0 |
|
BLAKE2b-256 | 9317dda0ff0f7137a5d3f8404e5b2a13363d646f0c13ab7beca4f84b6d68ffda |