Extend category_tree template tag

315 views
Skip to first unread message

Алексей Евсеев

unread,
Jul 1, 2013, 5:08:16 PM7/1/13
to django...@googlegroups.com
Hi guys,
recently i need to show only descendants categories of given category in template (i talk about oscar.apps.catalogue.models.Category). I've written my own template tag `category_tree_extended`, mostly copied from oscar's category_tree tag, with following syntax:

{% category_tree_extended [depth=n] [parent=<parent_category>] as categories %}

But i think, that it will be nice, if oscar's category_tree tag will have such functionality.
I have the code and can make a pull request.

Will it be useful?


Here are some examples:
suppose we have these categories:

    Vegetable
        Tomato
        Сucumber
    Fruit
        Сitrus
            Orange
            Lemon
        Banana

Now we can do in template:

{% category_tree parent=Fruit as tree_categories %}
tree_categories will have following categories:
        Сitrus
            Orange
            Lemon
        Banana

{% category_tree depth=1 parent=Fruit as tree_categories %}
tree_categories will have following categories:
        Сitrus
        Banana

{% category_tree as tree_categories %}
tree_categories will have following categories:
    Vegetable
        Tomato
        Сucumber
    Fruit
        Сitrus
            Orange
            Lemon
        Banana

Valery Sorokin

unread,
Jul 1, 2013, 5:16:53 PM7/1/13
to django...@googlegroups.com
Hi Alexey

Could you share your templatetag code. It seems very usefull.

I also vote for including this in oscar.

Valery

2013/7/2 Алексей Евсеев <alexe...@gmail.com>

--
https://github.com/tangentlabs/django-oscar
---
You received this message because you are subscribed to the Google Groups "django-oscar" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-oscar...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-oscar.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

David Winterbottom

unread,
Jul 2, 2013, 5:47:19 AM7/2/13
to django-oscar
Alexey

That looks interesting - I'd certainly be interested in a pull request.  

FYI, the category tree has been improved recently as part of #672 but solving a different problem to the one you mention.

In your example, what are you passing as the 'parent' option?  Is that a name or a category instance?  We have to be careful of i18n if passing names around - it's often better to use instances (or IDs).
--
David Winterbottom
Head of Programming

Tangent Labs
84-86 Great Portland Street
London W1W 7NR
England, UK

Алексей Евсеев

unread,
Jul 2, 2013, 7:58:16 AM7/2/13
to django...@googlegroups.com, david.win...@tangentlabs.co.uk
David

I wrote pseudo code in my examples above. Of course i mean a category instance, not a category name.

I've send a pull request https://github.com/tangentlabs/django-oscar/pull/741, please take a look there. Some tests are also attached.
Reply all
Reply to author
Forward
0 new messages