Skip to main content
100%

Nav mixin

✓ Published0🌍 Public
Aandybak
Last edited Jul 15, 2011
Created on Jul 15, 2011

This example shows a Django mixin for generating hierarchical navigation menus from a model tree, rendering nested `<ul>` and `<li>` structures with links or selected/ancestor states. The code uses `django.core.urlresolvers.reverse` for URL generation, `django.contrib.admin.site` for admin integration, and `django.utils.safestring.mark_safe` for safe HTML output. It relies on MPTT model methods like `get_ancestors`, `get_children`, and `get_siblings` to traverse the tree, filtering by `active` and `show_in_navigation` fields. The output is a string of nested HTML tags, with the current page rendered as a `<span>` and ancestors highlighted with CSS classes.

AI-generated description

Similar vizzes