1๐
โ
Use Navigation Modifiers like this.
In the myapp/menu.py:
from menus.base import NavigationNode
from menus.menu_pool import menu_pool
from cms.menu_bases import CMSAttachMenu
from models import Category, Post
class CategoryMenu(CMSAttachMenu):
name = ("Category Menu")
def get_nodes(self, request):
nodes = []
for category in Category.objects.all():
node = NavigationNode(
category.title,
category.get_absolute_url(),
category.pk,
)
nodes.append(node)
for post in Post.objects.filter(category=category):
node2 = NavigationNode(
post.title,
post.get_absolute_url(),
post.pk,
category.pk
)
nodes.append(node2)
return nodes
menu_pool.register_menu(CategoryMenu)
Now you can select the menu for page you hooked the app and display the breadcrumbs in the template.
Oh and you have to add get_absolute_url to the models:
https://docs.djangoproject.com/en/dev/ref/models/instances/#get-absolute-url
๐คcwirz
0๐
As django-cms documentation say:
If the current URL is not handled by the CMS or you are working in a navigation extender, you may need to provide your own breadcrumb via the template. This is mostly needed for pages like login, logout and third-party apps.
๐คniekas
- [Answer]-Error in modelformset_factory : matching query does not exist
- [Answer]-How do I test for a Bootstrap tour popover in Django?
- [Answer]-Modify data before creating model instance using django ModelForm
- [Answer]-How can I make my query set order by descending in django based on auto increment id field
Source:stackexchange.com