django-fast-treenode 2.1.0__py3-none-any.whl → 2.1.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {django_fast_treenode-2.1.0.dist-info → django_fast_treenode-2.1.2.dist-info}/METADATA +11 -14
- {django_fast_treenode-2.1.0.dist-info → django_fast_treenode-2.1.2.dist-info}/RECORD +7 -18
- {django_fast_treenode-2.1.0.dist-info → django_fast_treenode-2.1.2.dist-info}/WHEEL +1 -1
- treenode/__init__.py +5 -0
- treenode/version.py +2 -2
- treenode/docs/.gitignore +0 -0
- treenode/docs/about.md +0 -36
- treenode/docs/admin.md +0 -104
- treenode/docs/api.md +0 -739
- treenode/docs/cache.md +0 -187
- treenode/docs/import_export.md +0 -35
- treenode/docs/index.md +0 -30
- treenode/docs/installation.md +0 -74
- treenode/docs/migration.md +0 -145
- treenode/docs/models.md +0 -128
- treenode/docs/roadmap.md +0 -45
- {django_fast_treenode-2.1.0.dist-info → django_fast_treenode-2.1.2.dist-info}/LICENSE +0 -0
- {django_fast_treenode-2.1.0.dist-info → django_fast_treenode-2.1.2.dist-info}/top_level.txt +0 -0
treenode/docs/api.md
DELETED
@@ -1,739 +0,0 @@
|
|
1
|
-
## API Reference
|
2
|
-
|
3
|
-
### Overview
|
4
|
-
The `django-fast-treenode` package provides a **comprehensive set of methods and properties** for working with hierarchical data structures in Django. These methods are designed to simplify tree management, optimize performance, and facilitate migration from other tree-based Django packages.
|
5
|
-
|
6
|
-
The API is divided into several logical groups, each serving a specific purpose:
|
7
|
-
|
8
|
-
- **[TreeNodeModel Methods](#treenodemodel-methods)** – Core methods for managing tree nodes, including saving, deleting, and caching.
|
9
|
-
- **[Ancestor Methods](#ancestor-methods)** – Retrieve and manipulate ancestor nodes.
|
10
|
-
- **[Children Methods](#children-methods)** – Manage direct child nodes efficiently.
|
11
|
-
- **[Descendant Methods](#descendant-methods)** – Work with entire subtrees of nodes.
|
12
|
-
- **[Family Methods](#family-methods)** – Retrieve and analyze relationships within a node's family (ancestors, siblings, descendants).
|
13
|
-
- **[Node Utility Methods](#node-utility-methods)** – Additional methods for retrieving node order, paths, levels, and priorities.
|
14
|
-
- **[Root Node Methods](#root-node-methods)** – Manage and retrieve root nodes of trees.
|
15
|
-
- **[Sibling Methods](#sibling-methods)** – Handle relationships between sibling nodes.
|
16
|
-
- **[Tree Methods](#tree-methods)** – Serialize and manipulate the entire tree structure, including JSON export/import.
|
17
|
-
- **[Logical Methods](#logical-methods)** – Determine relationships between nodes (e.g., is ancestor, is sibling, is leaf).
|
18
|
-
- **[Property Accessors](#property-accessors)** – Shortcut properties for commonly used methods like `parent`, `children`, `siblings`, `depth`, and `priority`.
|
19
|
-
|
20
|
-
Each section below briefly describes the purpose of the respective method group.
|
21
|
-
|
22
|
-
---
|
23
|
-
|
24
|
-
### TreeNodeModel Methods
|
25
|
-
These methods handle the basic operations of the tree structure. They ensure that the data in the Adjacency Table and the Closure Table are synchronized. This section covers:
|
26
|
-
|
27
|
-
- Clearing the model cache.
|
28
|
-
- Deleting a node with different strategies.
|
29
|
-
- Saving a node while maintaining tree integrity.
|
30
|
-
|
31
|
-
#### clear_cache(cls):
|
32
|
-
A class method that **invalidates** (clears) the cache for a given model only.
|
33
|
-
```python
|
34
|
-
cls.clear_cache()
|
35
|
-
```
|
36
|
-
For more information on caching, see [Caching and Cache Management](cache.md)
|
37
|
-
|
38
|
-
|
39
|
-
#### delete
|
40
|
-
**Delete a node** provides two deletion strategies:
|
41
|
-
- **Cascade Delete (`cascade=True`)**: Removes the node along with all its descendants.
|
42
|
-
- **Reparenting (`cascade=False`)**: Moves the children of the deleted node up one level in the hierarchy before removing the node itself.
|
43
|
-
|
44
|
-
```python
|
45
|
-
obj.delete(cascade=True) # Deletes node and all its descendants
|
46
|
-
obj.delete(cascade=False) # Moves children up and then deletes the node
|
47
|
-
```
|
48
|
-
This ensures greater flexibility in managing tree structures while preventing orphaned nodes.
|
49
|
-
|
50
|
-
|
51
|
-
#### save
|
52
|
-
**Save a node** with Adjacency Sheet and Closure Tablet synchronizations.
|
53
|
-
|
54
|
-
```python
|
55
|
-
obj.save()
|
56
|
-
```
|
57
|
-
|
58
|
-
---
|
59
|
-
|
60
|
-
### Ancestor Methods
|
61
|
-
These methods allow retrieving **all ancestor nodes**, ordered from root to parent. They provide filtering options by depth, retrieval of primary keys for optimized queries, and counting functionality for analysis.
|
62
|
-
|
63
|
-
#### get_ancestors_queryset
|
64
|
-
Returns the **ancestors queryset** (ordered from parent to root):
|
65
|
-
```python
|
66
|
-
obj.get_ancestors_queryset(include_self=True, depth=None)
|
67
|
-
```
|
68
|
-
|
69
|
-
#### get_ancestors_pks
|
70
|
-
Returns the **ancestors pks** list:
|
71
|
-
```python
|
72
|
-
obj.get_ancestors_pks(include_self=True, depth=None)
|
73
|
-
```
|
74
|
-
|
75
|
-
#### get_ancestors
|
76
|
-
Returns a **list with all ancestors** (ordered from root to parent):
|
77
|
-
```python
|
78
|
-
obj.get_ancestors(include_self=True, depth=None)
|
79
|
-
```
|
80
|
-
|
81
|
-
#### get_ancestors_count
|
82
|
-
Returns the **ancestors count**:
|
83
|
-
```python
|
84
|
-
obj.get_ancestors_count(include_self=True, depth=None)
|
85
|
-
```
|
86
|
-
|
87
|
-
---
|
88
|
-
|
89
|
-
### Children Methods
|
90
|
-
These methods are designed to manage **direct child nodes** within the tree structure. They allow retrieving child nodes, counting them, and adding new children in a specific order (`first-child`, `last-child`, etc.).
|
91
|
-
|
92
|
-
#### add_child
|
93
|
-
```python
|
94
|
-
obj.add_child(position=None, **kwargs)
|
95
|
-
```
|
96
|
-
`position` specifies the order position of the object being added in the list of children of this node. It can be `'first-child'`, `'last-child'`, `'sorted-child'`, or an integer value.
|
97
|
-
The `**kwargs` parameters contain the object creation data that will be passed to the inherited node model. Instead of passing the object creation data, you can pass an already created (but not yet saved) model instance to insert into the tree using the `instance` keyword.
|
98
|
-
|
99
|
-
```python
|
100
|
-
obj.add_child(potision='first-child', instance=node)
|
101
|
-
```
|
102
|
-
|
103
|
-
The method returns the created node object. It will be saved by this method.
|
104
|
-
|
105
|
-
#### get_children_queryset
|
106
|
-
Returns the **children queryset**:
|
107
|
-
```python
|
108
|
-
obj.get_children_queryset()
|
109
|
-
```
|
110
|
-
|
111
|
-
#### get_children_pks
|
112
|
-
Returns the **children pks** list:
|
113
|
-
```python
|
114
|
-
obj.get_children_pks()
|
115
|
-
```
|
116
|
-
|
117
|
-
#### get_children
|
118
|
-
Returns a **list containing all children**:
|
119
|
-
```python
|
120
|
-
obj.get_children()
|
121
|
-
```
|
122
|
-
|
123
|
-
#### get_children_count
|
124
|
-
Returns the **children count**:
|
125
|
-
```python
|
126
|
-
obj.get_children_count()
|
127
|
-
```
|
128
|
-
|
129
|
-
#### get_first_child
|
130
|
-
Returns the **first child node** or `None` if it has no children:
|
131
|
-
```python
|
132
|
-
obj.get_first_child()
|
133
|
-
```
|
134
|
-
|
135
|
-
#### get_last_child
|
136
|
-
Returns the **last child node** or `None` if it has no children:
|
137
|
-
```python
|
138
|
-
obj.get_last_child()
|
139
|
-
```
|
140
|
-
|
141
|
-
---
|
142
|
-
|
143
|
-
### Descendant Methods
|
144
|
-
These methods enable working with **entire subtrees**. You can retrieve all descendants, filter by depth, count them, and fetch their primary keys for optimized queries.
|
145
|
-
|
146
|
-
#### get_descendants_queryset
|
147
|
-
Returns the **descendants queryset**:
|
148
|
-
```python
|
149
|
-
obj.get_descendants_queryset(include_self=False, depth=None)
|
150
|
-
```
|
151
|
-
|
152
|
-
#### get_descendants
|
153
|
-
Returns a **list containing all descendants**:
|
154
|
-
```python
|
155
|
-
obj.get_descendants(include_self=False, depth=None)
|
156
|
-
```
|
157
|
-
|
158
|
-
#### get_descendants_count
|
159
|
-
Returns the **descendants count**:
|
160
|
-
```python
|
161
|
-
obj.get_descendants_count(include_self=False, depth=None)
|
162
|
-
```
|
163
|
-
|
164
|
-
#### get_descendants_pks
|
165
|
-
Returns the **descendants pks** list:
|
166
|
-
```python
|
167
|
-
obj.get_descendants_pks(include_self=False, depth=None)
|
168
|
-
```
|
169
|
-
|
170
|
-
---
|
171
|
-
|
172
|
-
### Family Methods
|
173
|
-
These methods provide a comprehensive way to retrieve all related nodes within a tree, including ancestors, descendants, and siblings. They help analyze relationships while maintaining the correct tree order.
|
174
|
-
|
175
|
-
#### get_family_queryset
|
176
|
-
Returns a QuerySet containing the ancestors, itself and the descendants, in tree order.
|
177
|
-
```python
|
178
|
-
obj.get_family_queryset()
|
179
|
-
```
|
180
|
-
|
181
|
-
#### get_family_pks
|
182
|
-
Returns a pk-list containing the ancestors, the model itself and the descendants, in tree order:
|
183
|
-
```python
|
184
|
-
obj.get_family_pks()
|
185
|
-
```
|
186
|
-
|
187
|
-
#### get_family
|
188
|
-
Returns a list containing the ancestors, the model itself and the descendants, in tree order:
|
189
|
-
```python
|
190
|
-
obj.get_family()
|
191
|
-
```
|
192
|
-
|
193
|
-
#### get_family_count
|
194
|
-
Return number of nodes in family:
|
195
|
-
```python
|
196
|
-
obj.get_family()
|
197
|
-
```
|
198
|
-
|
199
|
-
---
|
200
|
-
|
201
|
-
### Node Utility Methods
|
202
|
-
This set of methods helps manage node-related operations such as:
|
203
|
-
|
204
|
-
- **Breadcrumbs generation**
|
205
|
-
- **Depth, index, and level calculations**
|
206
|
-
- **Materialized path retrieval for sorting**
|
207
|
-
- **Dynamic node positioning within the tree**
|
208
|
-
|
209
|
-
#### get_breadcrumbs
|
210
|
-
Returns the **breadcrumbs** to current node (included):
|
211
|
-
```python
|
212
|
-
obj.get_breadcrumbs(attr=None)
|
213
|
-
```
|
214
|
-
|
215
|
-
If `attr` is not specified, the method will return a list of pks ancestors, including itself.
|
216
|
-
|
217
|
-
#### get_depth
|
218
|
-
Returns the **node depth** (how deep is this level from the root of the tree; starting from 0):
|
219
|
-
```python
|
220
|
-
obj.get_depth()
|
221
|
-
```
|
222
|
-
|
223
|
-
#### get_level
|
224
|
-
Returns the **node level** (starting from 1):
|
225
|
-
```python
|
226
|
-
obj.get_level()
|
227
|
-
```
|
228
|
-
|
229
|
-
#### get_order
|
230
|
-
Returns the **order value** used for ordering:
|
231
|
-
```python
|
232
|
-
obj.get_order()
|
233
|
-
```
|
234
|
-
|
235
|
-
#### get_index
|
236
|
-
Returns the **node index** (index in children list):
|
237
|
-
```python
|
238
|
-
obj.get_index()
|
239
|
-
```
|
240
|
-
|
241
|
-
#### insert_at
|
242
|
-
Insert a node into the tree relative to the target node.
|
243
|
-
|
244
|
-
```python
|
245
|
-
obj.insert_at(target, position='first-child', save=False)
|
246
|
-
```
|
247
|
-
|
248
|
-
Parameters:
|
249
|
-
- `target`: еhe target node relative to which this node will be placed.
|
250
|
-
- `position`: the position, relative to the target node, where the current node object will be moved to, can be one of:
|
251
|
-
- `first-root`: the node will be the first root node;
|
252
|
-
- `last-root`: the node will be the last root node;
|
253
|
-
- `sorted-root`: the new node will be moved after sorting by the treenode_sort_field field;
|
254
|
-
- `first-sibling`: the node will be the new leftmost sibling of the target node;
|
255
|
-
- `left-sibling`: the node will take the target node’s place, which will be moved to the target position with shifting follows nodes;
|
256
|
-
- `right-sibling`: the node will be moved to the position after the target node;
|
257
|
-
- `last-sibling`: the node will be the new rightmost sibling of the target node;
|
258
|
-
- `sorted-sibling`: the new node will be moved after sorting by the treenode_sort_field field;
|
259
|
-
- first-child: the node will be the first child of the target node;
|
260
|
-
- last-child: the node will be the new rightmost child of the target
|
261
|
-
- sorted-child: the new node will be moved after sorting by the treenode_sort_field field.
|
262
|
-
- `save` : if `save=true`, the node will be saved in the tree. Otherwise, the method will return a model instance with updated fields: parent field and position in sibling list.
|
263
|
-
|
264
|
-
Before using this method, the model instance must be correctly created with all required fields defined. If the model has required fields, then simply creating an object and calling insert_at() will not work, because Django will raise an exception.
|
265
|
-
|
266
|
-
#### move_to
|
267
|
-
Moves the model instance relative to the target node and sets its position (if necessary).
|
268
|
-
```python
|
269
|
-
obj.move_to(target, position=0)
|
270
|
-
```
|
271
|
-
Parameters:
|
272
|
-
- `target`: еhe target node relative to which this node will be placed.
|
273
|
-
- `position` – the position, relative to the target node, where the current node object will be moved to. For detals see [insert_at](#insert_at) method.
|
274
|
-
|
275
|
-
#### get_path
|
276
|
-
Returns Materialized Path of node. The materialized path is constructed by recording the position of each node within its parent's list of children, tracing this sequence back through all its ancestors.
|
277
|
-
```python
|
278
|
-
obj.get_path(prefix='', suffix='', delimiter='.', format_str='')
|
279
|
-
```
|
280
|
-
|
281
|
-
#### get_parent
|
282
|
-
Returns the parent node.
|
283
|
-
```python
|
284
|
-
obj.get_parent()
|
285
|
-
```
|
286
|
-
|
287
|
-
#### set_parent
|
288
|
-
Sets the parent node.
|
289
|
-
```python
|
290
|
-
obj.set_parent(parent_obj)
|
291
|
-
```
|
292
|
-
|
293
|
-
#### get_parent_pk
|
294
|
-
Returns the parent node pk.
|
295
|
-
```python
|
296
|
-
obj.get_parent_pk()
|
297
|
-
```
|
298
|
-
|
299
|
-
#### get_priority
|
300
|
-
Returns the ordinal position of a node in its parent's list.
|
301
|
-
```python
|
302
|
-
obj.get_priority()
|
303
|
-
```
|
304
|
-
|
305
|
-
#### set_priority
|
306
|
-
Sets the ordinal position of a node in its parent's list. Takes an integer value as the `priority` parameter.
|
307
|
-
```python
|
308
|
-
obj.set_priority(priority=0)
|
309
|
-
```
|
310
|
-
|
311
|
-
If the `priority` value is found to be greater than the number of siblings, the node will be placed last in the list.
|
312
|
-
|
313
|
-
#### get_root
|
314
|
-
Returns the root node for the current node.
|
315
|
-
```python
|
316
|
-
obj.get_root()
|
317
|
-
```
|
318
|
-
|
319
|
-
#### get_root_pk
|
320
|
-
Returns the root node pk for the current node.
|
321
|
-
```python
|
322
|
-
obj.get_root_pk()
|
323
|
-
```
|
324
|
-
|
325
|
-
---
|
326
|
-
|
327
|
-
### Root Node Methods
|
328
|
-
These methods allow managing **root nodes** efficiently. They provide retrieval, counting, and manipulation of the first and last root nodes in the tree.
|
329
|
-
|
330
|
-
#### add_root
|
331
|
-
Adds a root node to the tree.
|
332
|
-
```python
|
333
|
-
cls.add_root(position=None, **kwargs)
|
334
|
-
```
|
335
|
-
|
336
|
-
Adds a new root node at the specified position. If no position is specified, the new node will be the last element in the root.
|
337
|
-
|
338
|
-
`position` specifies the order position of the object being added in the list of children of this node. It can be `'first-root'`, `'last-root'`, `'sorted-root'`, or an integer value.
|
339
|
-
|
340
|
-
The `**kwargs` parameters contain the object creation data that will be passed to the inherited node model. Instead of passing the object creation data, you can pass an already created (but not yet saved) model instance to insert into the tree using the `instance` keyword.
|
341
|
-
|
342
|
-
Returns the created node object. It will be saved by this method.
|
343
|
-
|
344
|
-
|
345
|
-
#### get_roots_queryset
|
346
|
-
Returns **root nodes queryset**:
|
347
|
-
```python
|
348
|
-
cls.get_roots_queryset()
|
349
|
-
```
|
350
|
-
|
351
|
-
#### get_roots
|
352
|
-
Returns a **list with all root nodes**:
|
353
|
-
```python
|
354
|
-
cls.get_roots()
|
355
|
-
```
|
356
|
-
|
357
|
-
#### get_roots_pks
|
358
|
-
Returns a **list with all root nodes pks**:
|
359
|
-
```python
|
360
|
-
cls.get_roots_pks()
|
361
|
-
```
|
362
|
-
|
363
|
-
#### get_roots_count
|
364
|
-
Returns **count of roots**:
|
365
|
-
```python
|
366
|
-
cls.get_roots_pks()
|
367
|
-
```
|
368
|
-
|
369
|
-
#### get_first_root
|
370
|
-
Returns the first root node in the tree or `None` if it is empty.
|
371
|
-
```python
|
372
|
-
cls.get_first_root()
|
373
|
-
```
|
374
|
-
|
375
|
-
#### get_last_root
|
376
|
-
Returns the last root node in the tree or `None` if it is empty.
|
377
|
-
```python
|
378
|
-
cls.get_last_root()
|
379
|
-
```
|
380
|
-
|
381
|
-
---
|
382
|
-
|
383
|
-
### Sibling Methods
|
384
|
-
These methods facilitate working with **sibling nodes** within the same hierarchy level. You can retrieve siblings, count them, or add new sibling nodes while maintaining the correct order.
|
385
|
-
|
386
|
-
#### add_sibling
|
387
|
-
Add a new node as a sibling to the current node object.
|
388
|
-
|
389
|
-
```python
|
390
|
-
obj.add_sibling(position=None, **kwargs):
|
391
|
-
```
|
392
|
-
|
393
|
-
`position` specifies the order position of the object being added in the list of children of this node. It can be `'first-sibling'`, `'left-sibling'`, `'right-sibling'`, `'last-sibling'`, `'sorted-sibling'`, or an integer value.
|
394
|
-
|
395
|
-
The `**kwargs` parameters contain the object creation data that will be passed to the inherited node model. Instead of passing the object creation data, you can pass an already created (but not yet saved) model instance to insert into the tree using the `instance` keyword.
|
396
|
-
|
397
|
-
Returns the created node object or `None` if failed. It will be saved by this method.
|
398
|
-
|
399
|
-
#### get_siblings_queryset
|
400
|
-
Returns the **siblings queryset**:
|
401
|
-
```python
|
402
|
-
obj.get_siblings_queryset()
|
403
|
-
```
|
404
|
-
|
405
|
-
#### get_siblings
|
406
|
-
Returns a **list with all the siblings**:
|
407
|
-
```python
|
408
|
-
obj.get_siblings()
|
409
|
-
# or
|
410
|
-
obj.siblings
|
411
|
-
```
|
412
|
-
|
413
|
-
#### get_siblings_pks
|
414
|
-
Returns the **siblings pks** list:
|
415
|
-
```python
|
416
|
-
obj.get_siblings_pks()
|
417
|
-
```
|
418
|
-
|
419
|
-
#### get_siblings_count
|
420
|
-
Returns the **siblings count**:
|
421
|
-
```python
|
422
|
-
obj.get_siblings_count()
|
423
|
-
```
|
424
|
-
|
425
|
-
#### get_first_sibling
|
426
|
-
Returns the fist node’s sibling.
|
427
|
-
|
428
|
-
```python
|
429
|
-
obj.get_first_sibling()
|
430
|
-
```
|
431
|
-
|
432
|
-
Method can return the node itself if it was the leftmost sibling.
|
433
|
-
|
434
|
-
#### get_previous_sibling
|
435
|
-
Returns the previous sibling in the tree, or `None`.
|
436
|
-
|
437
|
-
```python
|
438
|
-
obj.get_previous_sibling()
|
439
|
-
```
|
440
|
-
|
441
|
-
#### get_next_sibling
|
442
|
-
Returns the next sibling in the tree, or `None`.
|
443
|
-
|
444
|
-
```python
|
445
|
-
obj.get_next_sibling()
|
446
|
-
```
|
447
|
-
|
448
|
-
#### get_last_sibling
|
449
|
-
Returns the fist node's sibling.
|
450
|
-
|
451
|
-
```python
|
452
|
-
obj.get_next_sibling()
|
453
|
-
```
|
454
|
-
|
455
|
-
Method can return the node itself if it was the leftmost sibling.
|
456
|
-
|
457
|
-
---
|
458
|
-
|
459
|
-
### Tree Methods
|
460
|
-
These methods provide functionality for **serialization and manipulation of entire tree structures**. They include:
|
461
|
-
|
462
|
-
- Exporting the tree as a **JSON structure**
|
463
|
-
- Loading a tree from serialized data
|
464
|
-
- Generating **annotated representations** for UI display
|
465
|
-
- Rebuilding or deleting the entire tree structure
|
466
|
-
|
467
|
-
#### dump_tree
|
468
|
-
Return an **n-dimensional dictionary** representing the model tree.
|
469
|
-
|
470
|
-
```python
|
471
|
-
cls.dump_tree(instance=None)
|
472
|
-
```
|
473
|
-
|
474
|
-
Introduced for compatibility with other packages. In reality, [`get_tree()`](#get_tree) method is used.
|
475
|
-
|
476
|
-
This method is not recommended for use, as it **will be excluded in the future**.
|
477
|
-
|
478
|
-
#### get_tree
|
479
|
-
Return an **n-dimensional dictionary** representing the model tree.
|
480
|
-
|
481
|
-
```python
|
482
|
-
cls.get_tree(instance=None)
|
483
|
-
```
|
484
|
-
|
485
|
-
If instance is passed, returns a subtree rooted at instance (using `get_descendants_queryset`), if not passed, builds a tree for all nodes (loads all records in one query).
|
486
|
-
|
487
|
-
#### get_tree_json(cls, instance=None):
|
488
|
-
Represent the **tree as a JSON-compatible string**.
|
489
|
-
|
490
|
-
```python
|
491
|
-
cls.get_tree_json(instance=None)
|
492
|
-
```
|
493
|
-
|
494
|
-
#### load_tree(cls, tree_data):
|
495
|
-
**Load a tree** from a list of dictionaries.
|
496
|
-
|
497
|
-
```python
|
498
|
-
cls.load_tree(tree_data)
|
499
|
-
```
|
500
|
-
|
501
|
-
Loaded nodes are synchronized with the database: existing records are updated, new ones are created. Each dictionary must contain the `id` key to identify the record.
|
502
|
-
|
503
|
-
|
504
|
-
#### load_tree_json
|
505
|
-
Takes a JSON-compatible string and decodes it into a tree structure.
|
506
|
-
|
507
|
-
```python
|
508
|
-
cls.load_tree_json(json_str)
|
509
|
-
```
|
510
|
-
|
511
|
-
#### get_tree_display
|
512
|
-
Returns a **multiline string representing** the model tree.
|
513
|
-
|
514
|
-
```python
|
515
|
-
cls.get_tree_display(instance=None, symbol="—")
|
516
|
-
```
|
517
|
-
|
518
|
-
Inserts an indentation proportional to the node depth, filling it with the value of the `symbol` parameter.
|
519
|
-
|
520
|
-
#### get_tree_annotated
|
521
|
-
Returns an **annotated list** from a tree branch.
|
522
|
-
|
523
|
-
```python
|
524
|
-
cls.get_tree_annotated()
|
525
|
-
```
|
526
|
-
|
527
|
-
Something like this will be returned:
|
528
|
-
```python
|
529
|
-
[
|
530
|
-
(a, {'open':True, 'close':[], 'level': 0})
|
531
|
-
(ab, {'open':True, 'close':[], 'level': 1})
|
532
|
-
(aba, {'open':True, 'close':[], 'level': 2})
|
533
|
-
(abb, {'open':False, 'close':[], 'level': 2})
|
534
|
-
(abc, {'open':False, 'close':[0,1], 'level': 2})
|
535
|
-
(ac, {'open':False, 'close':[0], 'level': 1})
|
536
|
-
]
|
537
|
-
```
|
538
|
-
All nodes are ordered by materialized path.
|
539
|
-
|
540
|
-
This can be used with a template like this:
|
541
|
-
```html
|
542
|
-
{% for item, info in annotated_list %}
|
543
|
-
{% if info.open %}
|
544
|
-
<ul><li>
|
545
|
-
{% else %}
|
546
|
-
</li><li>
|
547
|
-
{% endif %}
|
548
|
-
|
549
|
-
{{ item }}
|
550
|
-
|
551
|
-
{% for close in info.close %}
|
552
|
-
</li></ul>
|
553
|
-
{% endfor %}
|
554
|
-
{% endfor %}
|
555
|
-
```
|
556
|
-
|
557
|
-
#### update_tree(cls):
|
558
|
-
**Rebuld tree** manually:
|
559
|
-
```python
|
560
|
-
cls.update_tree()
|
561
|
-
```
|
562
|
-
|
563
|
-
#### delete_tree
|
564
|
-
**Delete the whole tree** for the current node class.
|
565
|
-
|
566
|
-
```python
|
567
|
-
cls.delete_tree()
|
568
|
-
```
|
569
|
-
|
570
|
-
---
|
571
|
-
|
572
|
-
### Logical Methods
|
573
|
-
These methods provide boolean checks to determine relationships between nodes. They allow verifying whether a node is an ancestor, descendant, sibling, leaf, or root.
|
574
|
-
|
575
|
-
#### is_ancestor_of
|
576
|
-
Return `True` if the current node **is ancestor** of target_obj:
|
577
|
-
```python
|
578
|
-
obj.is_ancestor_of(target_obj)
|
579
|
-
```
|
580
|
-
|
581
|
-
#### is_child_of
|
582
|
-
Return `True` if the current node **is child** of target_obj:
|
583
|
-
```python
|
584
|
-
obj.is_child_of(target_obj)
|
585
|
-
```
|
586
|
-
|
587
|
-
#### is_descendant_of
|
588
|
-
Return `True` if the current node **is descendant** of target_obj:
|
589
|
-
```python
|
590
|
-
obj.is_descendant_of(target_obj)
|
591
|
-
```
|
592
|
-
|
593
|
-
#### is_first_child
|
594
|
-
Return `True` if the current node is the **first child**:
|
595
|
-
```python
|
596
|
-
obj.is_first_child()
|
597
|
-
```
|
598
|
-
|
599
|
-
#### is_last_child
|
600
|
-
Return `True` if the current node is the **last child**:
|
601
|
-
```python
|
602
|
-
obj.is_last_child()
|
603
|
-
```
|
604
|
-
|
605
|
-
#### is_leaf
|
606
|
-
Return `True` if the current node is **leaf** (it has not children):
|
607
|
-
```python
|
608
|
-
obj.is_leaf()
|
609
|
-
```
|
610
|
-
|
611
|
-
#### is_parent_of
|
612
|
-
Return `True` if the current node **is parent** of target_obj:
|
613
|
-
```python
|
614
|
-
obj.is_parent_of(target_obj)
|
615
|
-
```
|
616
|
-
|
617
|
-
#### is_root
|
618
|
-
Return `True` if the current node **is root**:
|
619
|
-
```python
|
620
|
-
obj.is_root()
|
621
|
-
```
|
622
|
-
|
623
|
-
#### is_root_of
|
624
|
-
Return `True` if the current node **is root** of target_obj:
|
625
|
-
```python
|
626
|
-
obj.is_root_of(target_obj)
|
627
|
-
```
|
628
|
-
|
629
|
-
#### is_sibling_of
|
630
|
-
Return `True` if the current node **is sibling** of target_obj:
|
631
|
-
```python
|
632
|
-
obj.is_sibling_of(target_obj)
|
633
|
-
```
|
634
|
-
|
635
|
-
---
|
636
|
-
|
637
|
-
### Property Accessors
|
638
|
-
These properties provide direct access to frequently used node attributes such as `parent`, `children`, `siblings`,`depth`, `level`, `priority`, `descendants`, `ancestors`, `family`.
|
639
|
-
|
640
|
-
They simplify access to node data without requiring explicit method calls.
|
641
|
-
|
642
|
-
#### obj.ancestors
|
643
|
-
Returns a list with all ancestors (itself included). See [`get_ancestors()`](#get_ancestors) method.
|
644
|
-
|
645
|
-
#### obj.ancestors_count
|
646
|
-
Returns the ancestors count. See [`get_ancestors_count()`](#get_ancestors_count) method.
|
647
|
-
|
648
|
-
#### obj.ancestors_pks
|
649
|
-
Returns the ancestors pks list (itself included). See [`get_ancestors_pks()`](#get_ancestors_pks) method.
|
650
|
-
|
651
|
-
#### obj.breadcrumbs
|
652
|
-
Returns the breadcrumbs to current node (itself included). See [`get_breadcrumbs()`](#get_breadcrumbs) method.
|
653
|
-
|
654
|
-
#### obj.children
|
655
|
-
Returns a list containing all children (itself included). See [`get_children()`](#get_children) method.
|
656
|
-
|
657
|
-
#### obj.children_count
|
658
|
-
Returns the children count. See [`get_children_count()`](#get_children_count) method.
|
659
|
-
|
660
|
-
#### obj.children_pks
|
661
|
-
Returns the children pks list. See [`get_children_pks()`](#get_children_pks) method.
|
662
|
-
|
663
|
-
#### obj.depth
|
664
|
-
Returns the node depth. See [`get_depth()`](#get_depth) method.
|
665
|
-
|
666
|
-
### obj.descendants:
|
667
|
-
Returns a list containing all descendants (itself is not included). See [`get_descendants()`](#get_descendants) method.
|
668
|
-
|
669
|
-
#### obj.descendants_count
|
670
|
-
Returns the descendants count (itself is not included). See [`get_descendants_count()`](#get_descendants_count) method.
|
671
|
-
|
672
|
-
#### obj.descendants_pks
|
673
|
-
Returns the descendants pks list (itself is not included). See [`get_descendants_pks()`](#get_descendants_pks) method.
|
674
|
-
|
675
|
-
#### obj.first_child
|
676
|
-
Returns the first child node. See [`get_first_child()`](#get_first_child) method.
|
677
|
-
|
678
|
-
#### obj.index
|
679
|
-
Returns the node index. See [`get_index()`](#get_index) method.
|
680
|
-
|
681
|
-
#### obj.last_child
|
682
|
-
Returns the last child node. See [`get_last_child()`](#get_last_child) method.
|
683
|
-
|
684
|
-
#### obj.level
|
685
|
-
Returns the node level. See [`get_level()`](#get_level) method.
|
686
|
-
|
687
|
-
#### obj.parent
|
688
|
-
Returns node parent. See [`get_patent()`](#get_patent) method.
|
689
|
-
|
690
|
-
#### obj.parent_pk
|
691
|
-
Returns node parent pk. See [`get_parent_pk()`](#get_parent_pk) method.
|
692
|
-
|
693
|
-
#### obj.priority
|
694
|
-
Returns node oder position (priority). See [`get_priority()`](#get_priority) method.
|
695
|
-
|
696
|
-
### cls.roots
|
697
|
-
Returns a list with all root nodes. See [`get_roots()`](#get_roots) method.
|
698
|
-
|
699
|
-
#### obj.root
|
700
|
-
Returns the root node for the current node. See [`get_root()`](#get_root) method.
|
701
|
-
|
702
|
-
#### obj.root_pk
|
703
|
-
Returns the root node pk for the current node. See [`get_root_pk()`](#get_root_pk) method.
|
704
|
-
|
705
|
-
#### obj.siblings
|
706
|
-
Get a list with all the siblings. See [`get_siblings()`](#get_siblings) method.
|
707
|
-
|
708
|
-
#### obj.siblings_count
|
709
|
-
Returns the siblings count. See [`get_siblings_count()`](#get_siblings_count) method.
|
710
|
-
|
711
|
-
#### obj.siblings_pks
|
712
|
-
Returns the siblings pks list. See [`get_siblings_pks()`](#get_siblings_pks) method.
|
713
|
-
|
714
|
-
#### cls.tree
|
715
|
-
Returns an n-dimensional dict representing the model tree. See [`get_tree()`](#get_tree) method.
|
716
|
-
|
717
|
-
#### cls.tree_display
|
718
|
-
Returns a multiline string representing the model tree. See [`get_tree_display()`](#get_tree_display) method.
|
719
|
-
|
720
|
-
**Warning**: Use with caution! Will be changed in future versions.
|
721
|
-
|
722
|
-
#### obj.tn_order
|
723
|
-
Return the materialized path. See [`get_order()`](#get_order) method.
|
724
|
-
|
725
|
-
**Warning**: Use with caution! Will be changed in future versions.
|
726
|
-
|
727
|
-
---
|
728
|
-
|
729
|
-
### Excluded methods
|
730
|
-
Some previously available methods have been replaced by new methods.
|
731
|
-
|
732
|
-
| Obsolete method | Desctiption | New implementation |
|
733
|
-
| ------------ | ------------ | ------------ |
|
734
|
-
| `get_descendants_tree()` | Returns a **n-dimensional** `dict` representing the **model tree** | [`cls.get_tree(cls, instance=None)`](#get_tree) |
|
735
|
-
| `get_descendants_tree_display()` | Returns a a **multiline** `string` representing the **model tree** | [`cls.get_tree_display(instance=None, symbol="—")`](#get_tree_display) |
|
736
|
-
|
737
|
-
---
|
738
|
-
|
739
|
-
The `django-fast-treenode` API provides a **robust, well-optimized**, and **extensible** interface for hierarchical data management in Django. Whether you're working with **large datasets** or **migrating from another tree-based package**, the methods are designed to be flexible and efficient.
|