One idea I've implemented before:
We have a model called Page that has fields for title and such. I
added a self-referential field called parent (a FK to itself) to
represent whether a Page is a child of another Page. If Page has a
parent, get the parent. If that Page has a parent, get its parent,
etc. You should eventually stop when parent is null. In that way,
you can climb up and output the breadcrumb...
I ended up with a breadcrumb function that looked like this:
def get_breadcrumb(page):
"""
Builds breadcrumbs separated by a right angle quotation (raquo)
"""
breadcrumb_list = [page.get_title()]
while page.parent:
page = page.parent
breadcrumb_list.insert(0, page.get_title()) # Insert title at
beginning of list
return ' » '.join(breadcrumb_list)
This was in my views.py but it could be in the model itself, I
suppose. For our purposes we also weren't making the breadcrumb
clickable, though with each page being an object you could easily add
that with page.get_absolute_url().
Cheers!
Rob
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---