Home python Django MPTT The withdrawal of all products from the parent category

Django MPTT The withdrawal of all products from the parent category

Author

Date

Category

Tell me how to get all products from the parent category. I have categories

[& lt; category: men & gt; Clothing & GT;, & lt; Category: Men & GT; Clothing & GT; Shirts & gt;, & lt; Category: Men & GT; Clothing & GT; T-shirts & gt;, & lt; Category: Men & GT; Footwear & gt;, & lt; Category: Men & GT; Footwear & gt; Sneakers & gt;].

How can I get all the products of the category of men Queryset? and T-shirts and sneakers and TD


Answer 1, Authority 100%

First, get a list of all subfolded subcategories inside [& lt; Category: Men & GT;]
to the desired number of nestedness

For example

category_man_id = ... # Point the starting upper category
Sub1 = List (Category.Objects.Filter (Parent = Category_man_id))
sub2 = list (Category.Objects.Filter (Parent__in = Sub1))
# You can dial in the cycle the desired number of nested
Products = Product.Objects.Filter (Category__in = Sub1 + Sub2)

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions