What's my mistake in doing the following in django-mptt? -
I have a category tree that has item entries related to category. So this is my model file:
I have manyToManyField Because each item can be in more than one category.
Now, after installing 'mptt' in my application, I am trying the following in shell:
category. Tree.add_related_count (category.red.root_nodes ( ), Which tree should be returned, and the number of items related to the node on each node, loading the item, 'category', 'q_c', cumulative = true)
. It looks like the standard functionality of django-mptt as described in this documentation.
P>
I implemented a very similar query for a site that is working manually Here is the code:
tree = Table 1. Object (select = {"tree_content_count": select "" "COUNT" (different% (join_table_fk1_name) s) From% (join_table) s WHERE% (Join_table_fk2_name) s (SELECT id FROM% (data_table) s2 where m2.tree_id =% (data_table)% between.t.t_ and m2.lft (data_table) s.lft and% (Data _table) s.rght) ""% {Params_dict_here}})
This trick seems to be a complete hierarchy; in other words, in five words, the "Five things" By putting, "Cheetah 2" has eight things and one of the "parent" counts the following:
Guardian (14) + - Child 1 (5) + - - Child 2 (8)
If you want a count in which things are included only at a particular level (and which are not below it in the hierarchy), then select the most select statement. Must Odit.
Comments
Post a Comment