Skip to Content
Menu
This question has been flagged


I have one model of the category with a child-parent relationship with itself.


class product_public_cate (models.Model):
    _name = "product.public.category"     parent_id = fields.Many2one ('product.public.category', 'parent category')


with many levels of child records, I want the main category and first child of the main category in the controller so fire a search method as below:

request.env ['product.public.category'].  search (['|', ('parent_id.parent_id', '=', False), ('parent_id', '=', False)], order = "parent_id desc")


It gives only the first child of the main category, not all main categories  

as I think there is some problem while comparing domain a parent_id.parent_id = false  
while there is no any parent_id.parent_id for main categories   

so wanted to know why this is happening ?  why I didn't get the main categories in the result is that a domain problem? 

thanks in advance.  



here are some queries that also I try but didn't get a result

request.env ['product.public.category']. search (['|', ('parent_id', '=', False), '&', ('parent_id', '! =', False), ('parent_id.parent_id', '=', False)] , order = "parent_id desc")


for 3 level child 
request.env ['product.public.category']. search (['!', ('parent_id.parent_id.parent_id', '=', False)])


Avatar
Discard
Related Posts Replies Views Activity
1
Nov 23
845
0
Sep 18
2226
0
Oct 17
8442
2
Jul 24
8845
1
Dec 23
7565