Hi,

Personally, I tend to keep the breadcrumb logic completely separate from
any custom code logic.

Instead, I have something like this:

context['breadcrumb'] = ['menu1', 'sub menu 2', 'sub sub menu 3']

And then in the templates, you'd have something like;

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

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

{% include "breadcrumb.html" %}

Although many would probably disagree with this approach, I have found that
keeping breadcrumbs completely separate makes things easier down the line..
Otherwise you end up having to create a breadcrumb system that works with
every use case.. and it often gets ugly.

The above is just my personal opinion based on our own specific use cases,
and I would strongly recommend looking around at alternative ways of doing
it, then finding one that suits what you need.

Hope this helps.

Cal

On Sat, Oct 13, 2012 at 9:53 PM, enemybass <[email protected]> wrote:

> 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> &gt;
> {% 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.
>

-- 
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.

Reply via email to