Breadcrump

Created on Oct. 14, 2012, 10:55 a.m. by Hevok & updated by Hevok on May 2, 2013, 5:23 p.m.

A breadcrumb is a navigation (rootline) which allows to keep track of the current locations within programs or documents.

To create a breadcrumb in a view the following approach could be utilized:

$ nano models.py
...
class Category(MPPTModel):
    name = models.CharField(max_length=50, verbose_name=u'Name')
    slug = modelsSlugField()
    parent = TreeForeignKey('self', null=True, blank=True, related_name='children')
...
class Entry(models.Model):
    name = models.CharField(max_length=50, verbose_name=u'Name')
    slug = models.SlugField()
    category = models.ManyToManyField('Category', verbose_name=u'Category')
$ nano views.py
...
def view(request, pk):
    entry = get_object_or_404(Entry, pk=pk)
    return render_to_response('entry_view.html', {'entry': entry},
         context_instance=RequestContext(request)
...
$ nano entry_view.html
...
{{ entry }}

In order to have a single view entry info ('entry_content') breadcrump with category. Something like this can be implemented: Category > Subcategory > Sub-Subcategory ... by using get_ancestor:

{% for parent in category.get_ancestor %}
    {{ parent.slug }}">{{ parent.name }}>
{% endfor %}
{{ category.title }}

The breadcrump can be kept completely separate from any custom code logic.

context['breadcrumb'] = ['menu1', 'sub menu2', 'sub sub menu3']

Then in the templates something like will be defined:

{% if x. == 'menu1' %}
     do something custom here
{% endfor %}

{% for x in breadcrumb %}
    {{ x }}
{% endfor %}

{% include "breadcrumb.html" %}
BreadCrumbs1.jpg

Tags: template, hierarchy, navigation, rest
Categories: Tutorial, reST
Parent: Web Framework

Update entry (Admin) | See changes

Comment on This Data Unit