django-fast-treenode 1.1.3__tar.gz → 2.0.1__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- django_fast_treenode-1.1.3/README.md → django_fast_treenode-2.0.1/PKG-INFO +134 -27
- django_fast_treenode-1.1.3/django_fast_treenode.egg-info/PKG-INFO → django_fast_treenode-2.0.1/README.md +92 -53
- django_fast_treenode-1.1.3/treenode/docs/Documentation → django_fast_treenode-2.0.1/django_fast_treenode.egg-info/PKG-INFO +143 -54
- django_fast_treenode-2.0.1/django_fast_treenode.egg-info/SOURCES.txt +47 -0
- django_fast_treenode-2.0.1/django_fast_treenode.egg-info/requires.txt +7 -0
- django_fast_treenode-2.0.1/pyproject.toml +29 -0
- {django_fast_treenode-1.1.3 → django_fast_treenode-2.0.1}/setup.cfg +14 -7
- django_fast_treenode-2.0.1/treenode/admin.py +381 -0
- django_fast_treenode-2.0.1/treenode/apps.py +23 -0
- django_fast_treenode-2.0.1/treenode/cache.py +231 -0
- django_fast_treenode-1.1.3/PKG-INFO → django_fast_treenode-2.0.1/treenode/docs/Documentation +92 -53
- django_fast_treenode-2.0.1/treenode/forms.py +88 -0
- django_fast_treenode-2.0.1/treenode/managers.py +281 -0
- django_fast_treenode-2.0.1/treenode/models/__init__.py +7 -0
- django_fast_treenode-2.0.1/treenode/models/classproperty.py +24 -0
- django_fast_treenode-2.0.1/treenode/models/closure.py +168 -0
- django_fast_treenode-2.0.1/treenode/models/factory.py +71 -0
- django_fast_treenode-2.0.1/treenode/models/proxy.py +650 -0
- django_fast_treenode-2.0.1/treenode/static/.gitkeep +0 -0
- django_fast_treenode-2.0.1/treenode/static/treenode/css/tree_widget.css +62 -0
- django_fast_treenode-2.0.1/treenode/static/treenode/css/treenode_admin.css +106 -0
- django_fast_treenode-2.0.1/treenode/static/treenode/js/tree_widget.js +161 -0
- django_fast_treenode-2.0.1/treenode/static/treenode/js/treenode_admin.js +171 -0
- django_fast_treenode-2.0.1/treenode/templates/admin/export_success.html +26 -0
- django_fast_treenode-2.0.1/treenode/templates/admin/tree_node_changelist.html +11 -0
- django_fast_treenode-2.0.1/treenode/templates/admin/tree_node_export.html +27 -0
- django_fast_treenode-2.0.1/treenode/templates/admin/tree_node_import.html +27 -0
- django_fast_treenode-2.0.1/treenode/templates/widgets/tree_widget.css +23 -0
- django_fast_treenode-2.0.1/treenode/templates/widgets/tree_widget.html +21 -0
- django_fast_treenode-2.0.1/treenode/urls.py +34 -0
- django_fast_treenode-2.0.1/treenode/utils/__init__.py +4 -0
- django_fast_treenode-2.0.1/treenode/utils/base36.py +35 -0
- django_fast_treenode-2.0.1/treenode/utils/exporter.py +141 -0
- django_fast_treenode-2.0.1/treenode/utils/importer.py +296 -0
- django_fast_treenode-2.0.1/treenode/version.py +13 -0
- django_fast_treenode-2.0.1/treenode/views.py +103 -0
- django_fast_treenode-2.0.1/treenode/widgets.py +65 -0
- django_fast_treenode-1.1.3/django_fast_treenode.egg-info/SOURCES.txt +0 -39
- django_fast_treenode-1.1.3/django_fast_treenode.egg-info/requires.txt +0 -1
- django_fast_treenode-1.1.3/pyproject.toml +0 -3
- django_fast_treenode-1.1.3/treenode/__init__.py +0 -7
- django_fast_treenode-1.1.3/treenode/admin.py +0 -136
- django_fast_treenode-1.1.3/treenode/apps.py +0 -6
- django_fast_treenode-1.1.3/treenode/compat.py +0 -8
- django_fast_treenode-1.1.3/treenode/factory.py +0 -68
- django_fast_treenode-1.1.3/treenode/forms.py +0 -32
- django_fast_treenode-1.1.3/treenode/managers.py +0 -69
- django_fast_treenode-1.1.3/treenode/models.py +0 -668
- django_fast_treenode-1.1.3/treenode/static/select2tree/select2tree.css +0 -176
- django_fast_treenode-1.1.3/treenode/static/select2tree/select2tree.js +0 -181
- django_fast_treenode-1.1.3/treenode/static/treenode/css/treenode.css +0 -85
- django_fast_treenode-1.1.3/treenode/static/treenode/js/treenode.js +0 -201
- django_fast_treenode-1.1.3/treenode/templates/.gitkeep +0 -1
- django_fast_treenode-1.1.3/treenode/templates/widgets/.gitkeep +0 -1
- django_fast_treenode-1.1.3/treenode/templates/widgets/attrs.html +0 -7
- django_fast_treenode-1.1.3/treenode/templates/widgets/options.html +0 -1
- django_fast_treenode-1.1.3/treenode/templates/widgets/select2tree.html +0 -22
- django_fast_treenode-1.1.3/treenode/tests.py +0 -3
- django_fast_treenode-1.1.3/treenode/version.py +0 -3
- django_fast_treenode-1.1.3/treenode/views.py +0 -3
- django_fast_treenode-1.1.3/treenode/widgets.py +0 -43
- {django_fast_treenode-1.1.3 → django_fast_treenode-2.0.1}/LICENSE +0 -0
- {django_fast_treenode-1.1.3 → django_fast_treenode-2.0.1}/MANIFEST.in +0 -0
- {django_fast_treenode-1.1.3 → django_fast_treenode-2.0.1}/django_fast_treenode.egg-info/dependency_links.txt +0 -0
- {django_fast_treenode-1.1.3 → django_fast_treenode-2.0.1}/django_fast_treenode.egg-info/top_level.txt +0 -0
- {django_fast_treenode-1.1.3 → django_fast_treenode-2.0.1}/setup.py +0 -0
- /django_fast_treenode-1.1.3/treenode/static/.gitkeep → /django_fast_treenode-2.0.1/treenode/__init__.py +0 -0
- {django_fast_treenode-1.1.3/treenode/docs → django_fast_treenode-2.0.1/treenode/static/treenode}/.gitkeep +0 -0
- {django_fast_treenode-1.1.3/treenode/static/select2tree → django_fast_treenode-2.0.1/treenode/static/treenode/css}/.gitkeep +0 -0
- {django_fast_treenode-1.1.3/treenode/static/treenode → django_fast_treenode-2.0.1/treenode/static/treenode/js}/.gitkeep +0 -0
- {django_fast_treenode-1.1.3/treenode/static/treenode/css → django_fast_treenode-2.0.1/treenode/templates}/.gitkeep +0 -0
- {django_fast_treenode-1.1.3/treenode/static/treenode/js → django_fast_treenode-2.0.1/treenode/templates/admin}/.gitkeep +0 -0
@@ -1,3 +1,45 @@
|
|
1
|
+
Metadata-Version: 2.2
|
2
|
+
Name: django-fast-treenode
|
3
|
+
Version: 2.0.1
|
4
|
+
Summary: Application for supporting tree (hierarchical) data structure in Django projects
|
5
|
+
Home-page: https://github.com/TimurKady/fast-treenode
|
6
|
+
Author: Timur Kady
|
7
|
+
Author-email: Timur Kady <timurkady@yandex.com>
|
8
|
+
License: MIT License
|
9
|
+
|
10
|
+
Copyright (c) 2020-2023 Timur Kady
|
11
|
+
|
12
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
13
|
+
of this software and associated documentation files (the "Software"), to deal
|
14
|
+
in the Software without restriction, including without limitation the rights
|
15
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
16
|
+
copies of the Software, and to permit persons to whom the Software is
|
17
|
+
furnished to do so, subject to the following conditions:
|
18
|
+
|
19
|
+
The above copyright notice and this permission notice shall be included in all
|
20
|
+
copies or substantial portions of the Software.
|
21
|
+
|
22
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
23
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
24
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
25
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
26
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
27
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
28
|
+
SOFTWARE.
|
29
|
+
Project-URL: Homepage, https://github.com/TimurKady/django-fast-treenode
|
30
|
+
Project-URL: Documentation, https://github.com/TimurKady/django-fast-treenode#readme
|
31
|
+
Project-URL: Source, https://github.com/TimurKady/django-fast-treenode
|
32
|
+
Project-URL: Issues, https://github.com/TimurKady/django-fast-treenode/issues
|
33
|
+
Requires-Python: >=3.9
|
34
|
+
Description-Content-Type: text/markdown
|
35
|
+
License-File: LICENSE
|
36
|
+
Requires-Dist: Django>=4.0
|
37
|
+
Requires-Dist: pympler>=1.0
|
38
|
+
Provides-Extra: import-export
|
39
|
+
Requires-Dist: openpyxl; extra == "import-export"
|
40
|
+
Requires-Dist: pyyaml; extra == "import-export"
|
41
|
+
Requires-Dist: pandas; extra == "import-export"
|
42
|
+
|
1
43
|
# Django-fast-treenode
|
2
44
|
__Combination of Adjacency List and Closure Table__
|
3
45
|
|
@@ -50,8 +92,7 @@ You can easily find additional information on your own on the Internet.
|
|
50
92
|
4. Make your model-admin inherit from ```treenode.admin.TreeNodeModelAdmin``` (described below)
|
51
93
|
5. Run python manage.py makemigrations and ```python manage.py migrate```
|
52
94
|
|
53
|
-
|
54
|
-
It will automatically build a new and complete Closure Table for your tree.
|
95
|
+
For more information on migrating from the **django-treenode** package and upgrading to version 2.0, see [below](#migration-guide).
|
55
96
|
|
56
97
|
## Configuration
|
57
98
|
### `models.py`
|
@@ -117,6 +158,8 @@ CACHES = {
|
|
117
158
|
},
|
118
159
|
"treenode": {
|
119
160
|
"BACKEND": "django.core.cache.backends.locmem.LocMemCache",
|
161
|
+
"KEY_PREFIX": "", # This is important!
|
162
|
+
"VERSION": None, # This is important!
|
120
163
|
},
|
121
164
|
}
|
122
165
|
```
|
@@ -124,15 +167,11 @@ CACHES = {
|
|
124
167
|
|
125
168
|
```
|
126
169
|
class YoursForm(TreeNodeForm):
|
127
|
-
|
128
|
-
class Meta:
|
129
|
-
widgets = {
|
130
|
-
'tn_parent': TreeWidget(attrs={'style': 'min-width:400px'}),
|
131
|
-
}
|
170
|
+
# Your code is here
|
132
171
|
```
|
133
172
|
|
134
|
-
## Usage
|
135
173
|
|
174
|
+
## Usage
|
136
175
|
### Methods/Properties
|
137
176
|
|
138
177
|
- [`delete`](#delete)
|
@@ -187,11 +226,17 @@ class YoursForm(TreeNodeForm):
|
|
187
226
|
- [`update_tree`](#update_tree)
|
188
227
|
|
189
228
|
#### `delete`
|
190
|
-
**Delete a node**
|
191
|
-
|
229
|
+
**Delete a node** provides two deletion strategies:
|
230
|
+
- **Cascade Delete (`cascade=True`)**: Removes the node along with all its descendants.
|
231
|
+
- **Reparenting (`cascade=False`)**: Moves the children of the deleted node up one level in the hierarchy before removing the node itself.
|
232
|
+
|
192
233
|
```python
|
193
|
-
|
234
|
+
node.delete(cascade=True) # Deletes node and all its descendants
|
235
|
+
node.delete(cascade=False) # Moves children up and then deletes the node
|
194
236
|
```
|
237
|
+
This ensures greater flexibility in managing tree structures while preventing orphaned nodes.
|
238
|
+
|
239
|
+
---
|
195
240
|
|
196
241
|
#### `delete_tree`
|
197
242
|
**Delete the whole tree** for the current node class:
|
@@ -313,6 +358,8 @@ obj.get_descendants_tree()
|
|
313
358
|
obj.descendants_tree
|
314
359
|
```
|
315
360
|
|
361
|
+
**Important**: In future projects, avoid using `get_descendants_tree()`. It will be removed in the next version.
|
362
|
+
|
316
363
|
#### `get_descendants_tree_display`
|
317
364
|
Get a **multiline** `string` representing the **model tree**:
|
318
365
|
```python
|
@@ -321,6 +368,8 @@ obj.get_descendants_tree_display(include_self=False, depth=None)
|
|
321
368
|
obj.descendants_tree_display
|
322
369
|
```
|
323
370
|
|
371
|
+
**Important**: In future projects, avoid using `get_descendants_tree_display()`. It will be removed in the next version.
|
372
|
+
|
324
373
|
#### `get_first_child`
|
325
374
|
Get the **first child node**:
|
326
375
|
```python
|
@@ -544,27 +593,85 @@ obj.is_sibling_of(target_obj)
|
|
544
593
|
```python
|
545
594
|
cls.update_tree()
|
546
595
|
```
|
596
|
+
## **Cache Management**
|
597
|
+
### **Overview**
|
598
|
+
In v2.0, the caching mechanism has been improved to prevent excessive memory usage when multiple models inherit from `TreeNode`. The new system introduces **FIFO (First-In-First-Out) cache eviction**, with plans to test and integrate more advanced algorithms in future releases.
|
599
|
+
|
600
|
+
### **Key Features**
|
601
|
+
**Global Cache Limit**: The setting `TREENODE_CACHE_LIMIT` defines the maximum cache size (in MB) for all models inheriting from `TreeNode`. Default is **100MB** if not explicitly set in `settings.py`.
|
602
|
+
**settings.py**
|
603
|
+
``` python
|
604
|
+
TREENODE_CACHE_LIMIT = 100
|
605
|
+
```
|
606
|
+
**Automatic Management**: In most cases, users don’t need to manually manage cache operations.
|
607
|
+
**Manual Cache Clearing**:
|
608
|
+
- **Clear cache for a single model**: Use `clear_cache()` at the model level:
|
609
|
+
```python
|
610
|
+
MyTreeNodeModel.clear_cache()
|
611
|
+
```
|
612
|
+
- **Clear cache for all models**: Use the global `treenode_cache.clear()` method:
|
613
|
+
```python
|
614
|
+
from treenode.cache import treenode_cache
|
615
|
+
treenode_cache.clear()
|
616
|
+
```
|
617
|
+
|
618
|
+
## **Export and Import Functionality**
|
619
|
+
### **Overview**
|
620
|
+
TreeNode v2.0 includes **built-in export and import features** for easier data migration. Supported Formats: `csv`, `json`, `xlsx`, `yaml`, `tsv`
|
621
|
+
### Installation for Import/Export Features
|
622
|
+
By default, import/export functionality is **not included** to keep the package lightweight. If you need these features, install the package with:
|
623
|
+
```bash
|
624
|
+
pip install django-fast-treenode[import_export]
|
625
|
+
```
|
626
|
+
Once installed, **import/export buttons will appear** in the Django admin interface.
|
627
|
+
### **Important Considerations**
|
628
|
+
Exporting objects with M2M fields may lead to serialization issues. Some formats (e.g., CSV) do not natively support many-to-many relationships. If you encounter errors, consider exporting data in `json` or `yaml` format, which better handle nested structures.
|
629
|
+
|
630
|
+
## Migration Guide
|
631
|
+
#### Switching from `django-treenode`
|
632
|
+
The migration process from `django-treenode` is fully automated. No manual steps are required. Upon upgrading, the necessary data structures will be checked and updated automatically. In exceptional cases, you can call the update code `cls.update_tree()` manually.
|
633
|
+
|
634
|
+
|
635
|
+
#### Upgrading to `django-fast-treenode` 2.0
|
636
|
+
To upgrade to version 2.0, simply run:
|
637
|
+
```bash
|
638
|
+
pip install --upgrade django-fast-treenode
|
639
|
+
```
|
640
|
+
or
|
641
|
+
```bash
|
642
|
+
pip install django-fast-treenode[import_export]
|
643
|
+
```
|
644
|
+
After upgrading, ensure that your database schema is up to date by running:
|
645
|
+
```bash
|
646
|
+
python manage.py makemigrations
|
647
|
+
python manage.py migrate
|
648
|
+
```
|
649
|
+
This will apply any necessary database changes automatically.
|
547
650
|
|
548
|
-
## License
|
549
|
-
Released under [MIT License](https://github.com/TimurKady/django-fast-treenode/blob/main/LICENSE).
|
550
651
|
|
551
|
-
##
|
552
|
-
|
652
|
+
## To do
|
653
|
+
These improvements aim to enhance usability, performance, and maintainability for all users of `django-fast-treenode`:
|
654
|
+
* **Cache Algorithm Optimization**: Testing and integrating more advanced cache eviction strategies.
|
655
|
+
* **Drag-and-Drop UI Enhancements**: Adding intuitive drag-and-drop functionality for tree node management.
|
656
|
+
* to be happy, to don't worry, until die.
|
553
657
|
|
554
|
-
|
658
|
+
Your wishes, objections, comments are welcome.
|
555
659
|
|
556
|
-
## Credits
|
557
|
-
This software contains, uses, including in a modified form:
|
558
|
-
* [django-treenode](https://github.com/fabiocaccamo/django-treenode) by [Fabio Caccamo](https://github.com/fabiocaccamo);
|
559
|
-
* [Select2-to-Tree](https://github.com/clivezhg/select2-to-tree) Select2 extension by [clivezhg](https://github.com/clivezhg)
|
560
660
|
|
561
|
-
|
661
|
+
# Django-fast-treenode
|
562
662
|
|
563
|
-
##
|
564
|
-
|
565
|
-
* may be will add the ability to determine the priority of the parent by any field, for example, by creation date or alphabetical order;
|
566
|
-
* drug-and-drop support;
|
567
|
-
* to be happy, to don't worry, until die.
|
663
|
+
## License
|
664
|
+
Released under [MIT License](https://github.com/TimurKady/django-fast-treenode/blob/main/LICENSE).
|
568
665
|
|
666
|
+
## Cautions
|
667
|
+
**Warning**: Do not access the tree node fields directly! Most of *django-treenode* model fields have been removed as unnecessary. Now only `tn_parent` and `tn_priority` are supported and will be kept in the future.
|
569
668
|
|
570
|
-
|
669
|
+
**Risks of Direct Field Access:**
|
670
|
+
- **Database Integrity Issues**: Directly modifying fields may break tree integrity, causing inconsistent parent-child relationships.
|
671
|
+
- **Loss of Cached Data**: The caching system relies on controlled updates. Bypassing methods like `set_parent()` or `update_tree()` may lead to outdated or incorrect data.
|
672
|
+
- **Unsupported Behavior**: Future versions may change field structures or remove unnecessary fields. Relying on them directly risks breaking compatibility.
|
673
|
+
|
674
|
+
Instead, always use the **documented methods** described above or refer to the [original application documentation](https://github.com/fabiocaccamo/django-treenode).
|
675
|
+
|
676
|
+
## Credits
|
677
|
+
This software contains, uses, and includes, in a modified form, [django-treenode](https://github.com/fabiocaccamo/django-treenode) by [Fabio Caccamo](https://github.com/fabiocaccamo). Special thanks to [Mathieu Leplatre](https://blog.mathieu-leplatre.info/pages/about.html) for the advice used in writing this application.
|
@@ -1,29 +1,3 @@
|
|
1
|
-
Metadata-Version: 2.1
|
2
|
-
Name: django-fast-treenode
|
3
|
-
Version: 1.1.3
|
4
|
-
Summary: Application for supporting tree (hierarchical) data structure in Django projects
|
5
|
-
Home-page: https://github.com/TimurKady/fast-treenode
|
6
|
-
Author: Timur Kady
|
7
|
-
Author-email: timurkady@yandex.com
|
8
|
-
License: MIT
|
9
|
-
Classifier: Environment :: Web Environment
|
10
|
-
Classifier: Framework :: Django
|
11
|
-
Classifier: Framework :: Django :: 3.0
|
12
|
-
Classifier: Intended Audience :: Developers
|
13
|
-
Classifier: License :: OSI Approved :: MIT License
|
14
|
-
Classifier: Operating System :: OS Independent
|
15
|
-
Classifier: Programming Language :: Python :: 3
|
16
|
-
Classifier: Programming Language :: Python :: 3.9
|
17
|
-
Classifier: Programming Language :: Python :: 3.10
|
18
|
-
Classifier: Programming Language :: Python :: 3.11
|
19
|
-
Classifier: Framework :: Django
|
20
|
-
Classifier: Framework :: Django :: 3.0
|
21
|
-
Classifier: Framework :: Django :: 4.0
|
22
|
-
Requires-Python: >=3.8
|
23
|
-
Description-Content-Type: text/markdown
|
24
|
-
License-File: LICENSE
|
25
|
-
Requires-Dist: Django>=3.0
|
26
|
-
|
27
1
|
# Django-fast-treenode
|
28
2
|
__Combination of Adjacency List and Closure Table__
|
29
3
|
|
@@ -76,8 +50,7 @@ You can easily find additional information on your own on the Internet.
|
|
76
50
|
4. Make your model-admin inherit from ```treenode.admin.TreeNodeModelAdmin``` (described below)
|
77
51
|
5. Run python manage.py makemigrations and ```python manage.py migrate```
|
78
52
|
|
79
|
-
|
80
|
-
It will automatically build a new and complete Closure Table for your tree.
|
53
|
+
For more information on migrating from the **django-treenode** package and upgrading to version 2.0, see [below](#migration-guide).
|
81
54
|
|
82
55
|
## Configuration
|
83
56
|
### `models.py`
|
@@ -143,6 +116,8 @@ CACHES = {
|
|
143
116
|
},
|
144
117
|
"treenode": {
|
145
118
|
"BACKEND": "django.core.cache.backends.locmem.LocMemCache",
|
119
|
+
"KEY_PREFIX": "", # This is important!
|
120
|
+
"VERSION": None, # This is important!
|
146
121
|
},
|
147
122
|
}
|
148
123
|
```
|
@@ -150,15 +125,11 @@ CACHES = {
|
|
150
125
|
|
151
126
|
```
|
152
127
|
class YoursForm(TreeNodeForm):
|
153
|
-
|
154
|
-
class Meta:
|
155
|
-
widgets = {
|
156
|
-
'tn_parent': TreeWidget(attrs={'style': 'min-width:400px'}),
|
157
|
-
}
|
128
|
+
# Your code is here
|
158
129
|
```
|
159
130
|
|
160
|
-
## Usage
|
161
131
|
|
132
|
+
## Usage
|
162
133
|
### Methods/Properties
|
163
134
|
|
164
135
|
- [`delete`](#delete)
|
@@ -213,11 +184,17 @@ class YoursForm(TreeNodeForm):
|
|
213
184
|
- [`update_tree`](#update_tree)
|
214
185
|
|
215
186
|
#### `delete`
|
216
|
-
**Delete a node**
|
217
|
-
|
187
|
+
**Delete a node** provides two deletion strategies:
|
188
|
+
- **Cascade Delete (`cascade=True`)**: Removes the node along with all its descendants.
|
189
|
+
- **Reparenting (`cascade=False`)**: Moves the children of the deleted node up one level in the hierarchy before removing the node itself.
|
190
|
+
|
218
191
|
```python
|
219
|
-
|
192
|
+
node.delete(cascade=True) # Deletes node and all its descendants
|
193
|
+
node.delete(cascade=False) # Moves children up and then deletes the node
|
220
194
|
```
|
195
|
+
This ensures greater flexibility in managing tree structures while preventing orphaned nodes.
|
196
|
+
|
197
|
+
---
|
221
198
|
|
222
199
|
#### `delete_tree`
|
223
200
|
**Delete the whole tree** for the current node class:
|
@@ -339,6 +316,8 @@ obj.get_descendants_tree()
|
|
339
316
|
obj.descendants_tree
|
340
317
|
```
|
341
318
|
|
319
|
+
**Important**: In future projects, avoid using `get_descendants_tree()`. It will be removed in the next version.
|
320
|
+
|
342
321
|
#### `get_descendants_tree_display`
|
343
322
|
Get a **multiline** `string` representing the **model tree**:
|
344
323
|
```python
|
@@ -347,6 +326,8 @@ obj.get_descendants_tree_display(include_self=False, depth=None)
|
|
347
326
|
obj.descendants_tree_display
|
348
327
|
```
|
349
328
|
|
329
|
+
**Important**: In future projects, avoid using `get_descendants_tree_display()`. It will be removed in the next version.
|
330
|
+
|
350
331
|
#### `get_first_child`
|
351
332
|
Get the **first child node**:
|
352
333
|
```python
|
@@ -570,27 +551,85 @@ obj.is_sibling_of(target_obj)
|
|
570
551
|
```python
|
571
552
|
cls.update_tree()
|
572
553
|
```
|
554
|
+
## **Cache Management**
|
555
|
+
### **Overview**
|
556
|
+
In v2.0, the caching mechanism has been improved to prevent excessive memory usage when multiple models inherit from `TreeNode`. The new system introduces **FIFO (First-In-First-Out) cache eviction**, with plans to test and integrate more advanced algorithms in future releases.
|
557
|
+
|
558
|
+
### **Key Features**
|
559
|
+
**Global Cache Limit**: The setting `TREENODE_CACHE_LIMIT` defines the maximum cache size (in MB) for all models inheriting from `TreeNode`. Default is **100MB** if not explicitly set in `settings.py`.
|
560
|
+
**settings.py**
|
561
|
+
``` python
|
562
|
+
TREENODE_CACHE_LIMIT = 100
|
563
|
+
```
|
564
|
+
**Automatic Management**: In most cases, users don’t need to manually manage cache operations.
|
565
|
+
**Manual Cache Clearing**:
|
566
|
+
- **Clear cache for a single model**: Use `clear_cache()` at the model level:
|
567
|
+
```python
|
568
|
+
MyTreeNodeModel.clear_cache()
|
569
|
+
```
|
570
|
+
- **Clear cache for all models**: Use the global `treenode_cache.clear()` method:
|
571
|
+
```python
|
572
|
+
from treenode.cache import treenode_cache
|
573
|
+
treenode_cache.clear()
|
574
|
+
```
|
575
|
+
|
576
|
+
## **Export and Import Functionality**
|
577
|
+
### **Overview**
|
578
|
+
TreeNode v2.0 includes **built-in export and import features** for easier data migration. Supported Formats: `csv`, `json`, `xlsx`, `yaml`, `tsv`
|
579
|
+
### Installation for Import/Export Features
|
580
|
+
By default, import/export functionality is **not included** to keep the package lightweight. If you need these features, install the package with:
|
581
|
+
```bash
|
582
|
+
pip install django-fast-treenode[import_export]
|
583
|
+
```
|
584
|
+
Once installed, **import/export buttons will appear** in the Django admin interface.
|
585
|
+
### **Important Considerations**
|
586
|
+
Exporting objects with M2M fields may lead to serialization issues. Some formats (e.g., CSV) do not natively support many-to-many relationships. If you encounter errors, consider exporting data in `json` or `yaml` format, which better handle nested structures.
|
587
|
+
|
588
|
+
## Migration Guide
|
589
|
+
#### Switching from `django-treenode`
|
590
|
+
The migration process from `django-treenode` is fully automated. No manual steps are required. Upon upgrading, the necessary data structures will be checked and updated automatically. In exceptional cases, you can call the update code `cls.update_tree()` manually.
|
591
|
+
|
592
|
+
|
593
|
+
#### Upgrading to `django-fast-treenode` 2.0
|
594
|
+
To upgrade to version 2.0, simply run:
|
595
|
+
```bash
|
596
|
+
pip install --upgrade django-fast-treenode
|
597
|
+
```
|
598
|
+
or
|
599
|
+
```bash
|
600
|
+
pip install django-fast-treenode[import_export]
|
601
|
+
```
|
602
|
+
After upgrading, ensure that your database schema is up to date by running:
|
603
|
+
```bash
|
604
|
+
python manage.py makemigrations
|
605
|
+
python manage.py migrate
|
606
|
+
```
|
607
|
+
This will apply any necessary database changes automatically.
|
573
608
|
|
574
|
-
## License
|
575
|
-
Released under [MIT License](https://github.com/TimurKady/django-fast-treenode/blob/main/LICENSE).
|
576
609
|
|
577
|
-
##
|
578
|
-
|
610
|
+
## To do
|
611
|
+
These improvements aim to enhance usability, performance, and maintainability for all users of `django-fast-treenode`:
|
612
|
+
* **Cache Algorithm Optimization**: Testing and integrating more advanced cache eviction strategies.
|
613
|
+
* **Drag-and-Drop UI Enhancements**: Adding intuitive drag-and-drop functionality for tree node management.
|
614
|
+
* to be happy, to don't worry, until die.
|
579
615
|
|
580
|
-
|
616
|
+
Your wishes, objections, comments are welcome.
|
581
617
|
|
582
|
-
## Credits
|
583
|
-
This software contains, uses, including in a modified form:
|
584
|
-
* [django-treenode](https://github.com/fabiocaccamo/django-treenode) by [Fabio Caccamo](https://github.com/fabiocaccamo);
|
585
|
-
* [Select2-to-Tree](https://github.com/clivezhg/select2-to-tree) Select2 extension by [clivezhg](https://github.com/clivezhg)
|
586
618
|
|
587
|
-
|
619
|
+
# Django-fast-treenode
|
588
620
|
|
589
|
-
##
|
590
|
-
|
591
|
-
* may be will add the ability to determine the priority of the parent by any field, for example, by creation date or alphabetical order;
|
592
|
-
* drug-and-drop support;
|
593
|
-
* to be happy, to don't worry, until die.
|
621
|
+
## License
|
622
|
+
Released under [MIT License](https://github.com/TimurKady/django-fast-treenode/blob/main/LICENSE).
|
594
623
|
|
624
|
+
## Cautions
|
625
|
+
**Warning**: Do not access the tree node fields directly! Most of *django-treenode* model fields have been removed as unnecessary. Now only `tn_parent` and `tn_priority` are supported and will be kept in the future.
|
595
626
|
|
596
|
-
|
627
|
+
**Risks of Direct Field Access:**
|
628
|
+
- **Database Integrity Issues**: Directly modifying fields may break tree integrity, causing inconsistent parent-child relationships.
|
629
|
+
- **Loss of Cached Data**: The caching system relies on controlled updates. Bypassing methods like `set_parent()` or `update_tree()` may lead to outdated or incorrect data.
|
630
|
+
- **Unsupported Behavior**: Future versions may change field structures or remove unnecessary fields. Relying on them directly risks breaking compatibility.
|
631
|
+
|
632
|
+
Instead, always use the **documented methods** described above or refer to the [original application documentation](https://github.com/fabiocaccamo/django-treenode).
|
633
|
+
|
634
|
+
## Credits
|
635
|
+
This software contains, uses, and includes, in a modified form, [django-treenode](https://github.com/fabiocaccamo/django-treenode) by [Fabio Caccamo](https://github.com/fabiocaccamo). Special thanks to [Mathieu Leplatre](https://blog.mathieu-leplatre.info/pages/about.html) for the advice used in writing this application.
|