I am using using Django to create custom CMS, where pages are stored in a 
hierarchy (implemented using django-mptt).

On a given child page, I want to show the links to all its siblings.

Currently, I am doing this with the help of a template tag which looks  
like this:


@register.inclusion_tag("wiki/_subpage_list.html")
def subpages(page):
    pages = {}
    if page.is_leaf_node() and not page.is_root_node():
        pages = page.get_siblings(include_self=True)
    return {'subpages': pages, 'page': page}


The problem with this approach is if there are 50 siblings of the page, 
there would be 50 sql queries. 

As far as I know In raw SQL I could get the list of siblings in two 
queries: first, to get the paent node, second, retrieve all the descendents 
of the parent node.

How can I do this more efficiently usins Django ORM?

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/843cfb2a-c709-48b0-89ec-5852680136aeo%40googlegroups.com.

Reply via email to