Answer the question
In order to leave comments, you need to log in
MPTT and incomplete tree - how to render it?
Hey!
There is mptt and django.
Let's say there are tasks in the form of a tree and tags for tasks. Since you can’t just add tags (there will be tree corruption during selections), I decided to make such logic so that the tags of the parent tasks are a subset of the tags of the children, but at the same time so that the children can have their own independent tags.
Thus, this tree will be valid:
Task 1; Tag 1
Task 2; Tag 1, Tag 2
Task 3; Tag 1, Tag 3
Task 4; Tag 1, Tag 3, Tag 4
The problem is in the selections by tags. Although fetching on Tag 3 in this example will not break the tree (there will be no gaps between nesting levels), MPTT template tags don't want to render such a tree, they just don't render it on the page. Probably because the root node is missing.
I suppose the solution to the problem lies in rewriting their template tags, but I have absolutely no idea how nested sets work and how template tags work, and it would take a lot of time to just teach MPTT such a primitive. Maybe you know an easier solution? :)
UPD.
Apparently, I was unclear. The problem is specifically at the template stage. I have a valid fetch which template tag recursetreedoesn't want to render because I guess it can't render from a non-root node. The question is specific: how to fix it or is it possible to bike with little blood?
One solution has already surfaced: to make a full selection (including those with parents who do not have this tag), but on the template side, check for the presence of the desired tag. No tag - walk. But it's a bike, of course.
Answer the question
In order to leave comments, you need to log in
I believe that using mptt (as well as nested sets in general) is redundant for such tasks. It is generally needed mainly only where there is an active rearrangement of nodes. The fact that it is sculpted wherever it hits does not indicate the correctness of such a decision to use it.
If I were you, I would just link the tasks through the usual FK to myself and do it through the usual links. At the same time, I would limit the number of nestings (10 pieces?). It will be easier.
If you still want to use mptt, I remember it had a good api, you can easily find a task by tags, then through a getParrent type method (I don’t remember exactly what it’s called), get to the parent and display it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question