How to create breadcrumb in my view function?
class Category(MPTTModel):
name = models.CharField(max_length=50, verbose_name=u'Name')
parent = TreeForeignKey('self', null=True, blank=True, related_name='children')
slug = models.SlugField()
class Product(models.Model):
name = models.CharField(max_length=50, verbose_name=u'Name')
slug = models.SlugField()
category = models.ManyToManyField(Category, verbose_name=u'Category')
#views
def post_content(request, product_id):
product = get_object_or_404(Product, id = product_id)
return render_to_response('product_info.html', {'product':product},context_instance=RequestContext(request))
product_info.html
I want in my single post info (`post_content`) breadcrumb with category.
Something like this: Category > Subcategory > Sub-Subcategory .,,,
Someone told me to use get_ancestors:
Example:
{% for parent in category.get_ancestors %}
{% endfor %}
How to implement this with my model?
Thank you. I would be grateful.