I know that there are many questions, but I can’t find the information I need for my situation, so I ask a new question.
Some suggestion: I use a hierarchical package for my models and a built-in function that generates a tree structure, outputs a nested loop to indicate parents, children, etc. My goal is to preserve the logic in the views and outputs of the list so that I can simply iterate over it in my templates.
Here are my data in the tree structure:
1
-1.1
--1.1.1
---1.1.1.1
--1.1.2
-1.2
--1.2.1
--1.2.2
-1.3
Here is the nested dictionary that I get as a result
{
<Part: 1.1>:
{
<Part: 1.1.1>:
{
<Part: 1.1.1.1>: {}
},
<Part: 1.1.2>: {}
},
<Part: 1.2>:
{
<Part: 1.2.1>: {},
<Part: 1.2.2>: {}
},
<Part: 1.3>: {}
}
or if you don’t like the way I tried to break it, here is what I get in one line:
{<Part: 1.1>: {<Part: 1.1.1>: {<Part: 1.1.1.1>: {}}, <Part: 1.1.2>: {}}, <Part: 1.2>: {<Part: 1.2.1>: {}, <Part: 1.2.2>: {}}, <Part: 1.3>: {}}
I want to receive:
[<Part: 1.1>, <Part: 1.1.1>, <Part: 1.1.1.1>, <Part: 1.1.2>, <Part: 1.2>, <Part: 1.2.2>, <Part: 1.2.1>, <Part: 1.3>,]
I tried just iterating over the key in the dict.items file, but then I get only the top-level keys (1.1, 1.2, 1.3)
, ?
!