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
{{ product.name }}
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 %}
<a href="{{ parent }}">{{ parent.name }}</a> >
{% endfor %}
{{ category.name }}
How to implement this with my model?
Thank you. I would be grateful.
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/django-users/-/ivQ6G2h8UT0J.
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.