[Answer]-How do I integrate a custom app to use breadcrumbs?

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

Leave a comment