Good day! Tell me please. The site has a catalog of products, django-mptt is used for the section structure, is there any standard opportunity to build bread crumbs using the code of the section being browsed?

For example:

Women -> shoes -> shoes -> without a heel

Models look like this:

class Category(MPTTModel): name = models.CharField('Раздел', max_length=100) parent = TreeForeignKey('self', null=True, blank=True, related_name='children', db_index=True) sort = models.SmallIntegerField('Сортировка', default=100) class Product(models.Model): parent = models.ForeignKey(Category) name = models.CharField('Название', max_length=100) # .... 

    1 answer 1

    Resolved!

    * templatetags *

     @register.inclusion_tag('catalog/template_tags/breadcrumb.html') def catalog_breadcrumb(category): return { 'category': category } 

    * breadcrumb.html *

     <ul> {% for parent in category.get_ancestors %} <li><a href="/catalog/{{ parent.slug }}/">{{ parent.name }}</a></li> {% endfor %} <li><a href="/catalog/{{ category.slug }}/">{{ category.name }}</a></li> </ul>