Product Categories

80 views
Skip to first unread message

tech george

unread,
May 21, 2021, 2:31:38 PM5/21/21
to django...@googlegroups.com
Hello,

I need your help with rendering main category products only to the page, currently the code seems to be picking even sub category products.

Please see below screenshots.


category model.png
category model 2.png

views.png
category products.png

category.html code.png

Please advise.

N'BE SORO

unread,
May 22, 2021, 11:31:23 AM5/22/21
to django...@googlegroups.com
Hi,
if you use MPTT templates, in your template use {% load mptt_tags %}

And you can proceed as follows for the display

{% load mptt_tags %}
<ul>
    {% recursetree genres %}
        <li>
            {{ node.name }}
            {% if not node.is_leaf_node %}
                <ul class="children">
                    {{ children }}
                </ul>
            {% endif %}
        </li>
    {% endrecursetree %} 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CADYG20H6qB4GTVq1J%3D6GcR%2BEu_r53pk-X%3DKvbosMrRrVz9jLYQ%40mail.gmail.com.

tech george

unread,
May 22, 2021, 1:11:35 PM5/22/21
to django...@googlegroups.com, soro...@gmail.com
Hi Soro,

Is there a way I can fetch the data without using MPTT?


tech george

unread,
May 22, 2021, 1:17:54 PM5/22/21
to django...@googlegroups.com, soro...@gmail.com
I already use recursetree on my sidebar.html

I wanted to get the parent category list with images on another section of my app (category.html)

Patrick Café

unread,
May 22, 2021, 2:14:47 PM5/22/21
to django...@googlegroups.com

N'BE SORO

unread,
May 22, 2021, 2:48:21 PM5/22/21
to django...@googlegroups.com
Ok use:

# In Python
# print(category.get_ancestors())
# In Jinja category.get_ancestors

tech george

unread,
May 23, 2021, 3:55:22 AM5/23/21
to django...@googlegroups.com, soro...@gmail.com
Thanks Work,

Let me try that.

Regards.

Reply all
Reply to author
Forward
0 new messages