django-fast-treenode 1.1.2__tar.gz → 2.0.0__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. django-fast-treenode-1.1.2/README.md → django_fast_treenode-2.0.0/PKG-INFO +163 -27
  2. django-fast-treenode-1.1.2/django_fast_treenode.egg-info/PKG-INFO → django_fast_treenode-2.0.0/README.md +121 -51
  3. django-fast-treenode-1.1.2/treenode/docs/Documentation → django_fast_treenode-2.0.0/django_fast_treenode.egg-info/PKG-INFO +172 -54
  4. django_fast_treenode-2.0.0/django_fast_treenode.egg-info/SOURCES.txt +47 -0
  5. django_fast_treenode-2.0.0/django_fast_treenode.egg-info/requires.txt +7 -0
  6. django_fast_treenode-2.0.0/pyproject.toml +29 -0
  7. {django-fast-treenode-1.1.2 → django_fast_treenode-2.0.0}/setup.cfg +16 -7
  8. django_fast_treenode-2.0.0/treenode/admin.py +381 -0
  9. django_fast_treenode-2.0.0/treenode/apps.py +23 -0
  10. django_fast_treenode-2.0.0/treenode/cache.py +231 -0
  11. django-fast-treenode-1.1.2/PKG-INFO → django_fast_treenode-2.0.0/treenode/docs/Documentation +121 -51
  12. django_fast_treenode-2.0.0/treenode/forms.py +88 -0
  13. django_fast_treenode-2.0.0/treenode/managers.py +281 -0
  14. django_fast_treenode-2.0.0/treenode/models/__init__.py +7 -0
  15. django_fast_treenode-2.0.0/treenode/models/classproperty.py +24 -0
  16. django_fast_treenode-2.0.0/treenode/models/closure.py +168 -0
  17. django_fast_treenode-2.0.0/treenode/models/factory.py +71 -0
  18. django_fast_treenode-2.0.0/treenode/models/proxy.py +650 -0
  19. django_fast_treenode-2.0.0/treenode/static/.gitkeep +0 -0
  20. django_fast_treenode-2.0.0/treenode/static/treenode/css/tree_widget.css +62 -0
  21. django_fast_treenode-2.0.0/treenode/static/treenode/css/treenode_admin.css +106 -0
  22. django_fast_treenode-2.0.0/treenode/static/treenode/js/tree_widget.js +161 -0
  23. django_fast_treenode-2.0.0/treenode/static/treenode/js/treenode_admin.js +171 -0
  24. django_fast_treenode-2.0.0/treenode/templates/admin/export_success.html +26 -0
  25. django_fast_treenode-2.0.0/treenode/templates/admin/tree_node_changelist.html +11 -0
  26. django_fast_treenode-2.0.0/treenode/templates/admin/tree_node_export.html +27 -0
  27. django_fast_treenode-2.0.0/treenode/templates/admin/tree_node_import.html +27 -0
  28. django_fast_treenode-2.0.0/treenode/templates/widgets/tree_widget.css +23 -0
  29. django_fast_treenode-2.0.0/treenode/templates/widgets/tree_widget.html +21 -0
  30. django_fast_treenode-2.0.0/treenode/urls.py +34 -0
  31. django_fast_treenode-2.0.0/treenode/utils/__init__.py +4 -0
  32. django_fast_treenode-2.0.0/treenode/utils/base36.py +35 -0
  33. django_fast_treenode-2.0.0/treenode/utils/exporter.py +141 -0
  34. django_fast_treenode-2.0.0/treenode/utils/importer.py +296 -0
  35. django_fast_treenode-2.0.0/treenode/version.py +13 -0
  36. django_fast_treenode-2.0.0/treenode/views.py +103 -0
  37. django_fast_treenode-2.0.0/treenode/widgets.py +65 -0
  38. django-fast-treenode-1.1.2/django_fast_treenode.egg-info/SOURCES.txt +0 -39
  39. django-fast-treenode-1.1.2/django_fast_treenode.egg-info/requires.txt +0 -1
  40. django-fast-treenode-1.1.2/pyproject.toml +0 -3
  41. django-fast-treenode-1.1.2/treenode/__init__.py +0 -7
  42. django-fast-treenode-1.1.2/treenode/admin.py +0 -136
  43. django-fast-treenode-1.1.2/treenode/apps.py +0 -6
  44. django-fast-treenode-1.1.2/treenode/compat.py +0 -8
  45. django-fast-treenode-1.1.2/treenode/factory.py +0 -68
  46. django-fast-treenode-1.1.2/treenode/forms.py +0 -32
  47. django-fast-treenode-1.1.2/treenode/managers.py +0 -69
  48. django-fast-treenode-1.1.2/treenode/models.py +0 -669
  49. django-fast-treenode-1.1.2/treenode/static/select2tree/select2tree.css +0 -176
  50. django-fast-treenode-1.1.2/treenode/static/select2tree/select2tree.js +0 -171
  51. django-fast-treenode-1.1.2/treenode/static/treenode/css/treenode.css +0 -85
  52. django-fast-treenode-1.1.2/treenode/static/treenode/js/treenode.js +0 -201
  53. django-fast-treenode-1.1.2/treenode/templates/.gitkeep +0 -1
  54. django-fast-treenode-1.1.2/treenode/templates/widgets/.gitkeep +0 -1
  55. django-fast-treenode-1.1.2/treenode/templates/widgets/attrs.html +0 -7
  56. django-fast-treenode-1.1.2/treenode/templates/widgets/options.html +0 -1
  57. django-fast-treenode-1.1.2/treenode/templates/widgets/select2tree.html +0 -22
  58. django-fast-treenode-1.1.2/treenode/tests.py +0 -3
  59. django-fast-treenode-1.1.2/treenode/version.py +0 -3
  60. django-fast-treenode-1.1.2/treenode/views.py +0 -3
  61. django-fast-treenode-1.1.2/treenode/widgets.py +0 -43
  62. {django-fast-treenode-1.1.2 → django_fast_treenode-2.0.0}/LICENSE +0 -0
  63. {django-fast-treenode-1.1.2 → django_fast_treenode-2.0.0}/MANIFEST.in +0 -0
  64. {django-fast-treenode-1.1.2 → django_fast_treenode-2.0.0}/django_fast_treenode.egg-info/dependency_links.txt +0 -0
  65. {django-fast-treenode-1.1.2 → django_fast_treenode-2.0.0}/django_fast_treenode.egg-info/top_level.txt +0 -0
  66. {django-fast-treenode-1.1.2 → django_fast_treenode-2.0.0}/setup.py +0 -0
  67. /django-fast-treenode-1.1.2/treenode/static/.gitkeep → /django_fast_treenode-2.0.0/treenode/__init__.py +0 -0
  68. {django-fast-treenode-1.1.2/treenode/docs → django_fast_treenode-2.0.0/treenode/static/treenode}/.gitkeep +0 -0
  69. {django-fast-treenode-1.1.2/treenode/static/select2tree → django_fast_treenode-2.0.0/treenode/static/treenode/css}/.gitkeep +0 -0
  70. {django-fast-treenode-1.1.2/treenode/static/treenode → django_fast_treenode-2.0.0/treenode/static/treenode/js}/.gitkeep +0 -0
  71. {django-fast-treenode-1.1.2/treenode/static/treenode/css → django_fast_treenode-2.0.0/treenode/templates}/.gitkeep +0 -0
  72. {django-fast-treenode-1.1.2/treenode/static/treenode/js → django_fast_treenode-2.0.0/treenode/templates/admin}/.gitkeep +0 -0
@@ -1,3 +1,45 @@
1
+ Metadata-Version: 2.2
2
+ Name: django-fast-treenode
3
+ Version: 2.0.0
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 <kaduevtr@gmail.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<5.0,>=3.2
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
- When updating an existing project, simply call ```cls.update_tree()``` function once.
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,42 @@ 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
173
+ ## Updating to django-fast-treenode 2.X
174
+ ### Overview
175
+ If you are upgrading from a previous version, you need to follow these steps to ensure compatibility and proper functionality.
176
+
177
+ ### Update Process
178
+ 1. **Upgrade the package**
179
+ Run the following command to install the latest version:
180
+
181
+ ```bash
182
+ pip install --upgrade django-fast-treenode
183
+ ```
184
+
185
+ 2. **Apply database migrations**
186
+ After upgrading, you need to apply the necessary database migrations:
187
+
188
+ ```bash
189
+ python manage.py makemigrations
190
+ python manage.py migrate
191
+ ```
192
+
193
+ 3. **Restart the application**
194
+ Finally, restart your Django application to apply all changes:
135
195
 
196
+ ```bash
197
+ python manage.py runserver
198
+ ```
199
+
200
+ **Important Notes**: Failing to apply migrations (`migrate`) after upgrading may lead to errors when interacting with tree nodes.
201
+
202
+ By following these steps, you will ensure a smooth transition to the latest version of django-fast-treenode without data inconsistencies.
203
+
204
+
205
+ ## Usage
136
206
  ### Methods/Properties
137
207
 
138
208
  - [`delete`](#delete)
@@ -187,11 +257,17 @@ class YoursForm(TreeNodeForm):
187
257
  - [`update_tree`](#update_tree)
188
258
 
189
259
  #### `delete`
190
- **Delete a node** if `cascade=True` (default behaviour), children and descendants will be deleted too,
191
- otherwise children's parent will be set to `None` (then children become roots):
260
+ **Delete a node** provides two deletion strategies:
261
+ - **Cascade Delete (`cascade=True`)**: Removes the node along with all its descendants.
262
+ - **Reparenting (`cascade=False`)**: Moves the children of the deleted node up one level in the hierarchy before removing the node itself.
263
+
192
264
  ```python
193
- obj.delete(cascade=True)
265
+ node.delete(cascade=True) # Deletes node and all its descendants
266
+ node.delete(cascade=False) # Moves children up and then deletes the node
194
267
  ```
268
+ This ensures greater flexibility in managing tree structures while preventing orphaned nodes.
269
+
270
+ ---
195
271
 
196
272
  #### `delete_tree`
197
273
  **Delete the whole tree** for the current node class:
@@ -313,6 +389,8 @@ obj.get_descendants_tree()
313
389
  obj.descendants_tree
314
390
  ```
315
391
 
392
+ **Important**: In future projects, avoid using `get_descendants_tree()`. It will be removed in the next version.
393
+
316
394
  #### `get_descendants_tree_display`
317
395
  Get a **multiline** `string` representing the **model tree**:
318
396
  ```python
@@ -321,6 +399,8 @@ obj.get_descendants_tree_display(include_self=False, depth=None)
321
399
  obj.descendants_tree_display
322
400
  ```
323
401
 
402
+ **Important**: In future projects, avoid using `get_descendants_tree_display()`. It will be removed in the next version.
403
+
324
404
  #### `get_first_child`
325
405
  Get the **first child node**:
326
406
  ```python
@@ -544,27 +624,83 @@ obj.is_sibling_of(target_obj)
544
624
  ```python
545
625
  cls.update_tree()
546
626
  ```
627
+ ## **Cache Management**
628
+ ### **Overview**
629
+ 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.
630
+
631
+ ### **Key Features**
632
+ **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`.
633
+ **settings.py**
634
+ ``` python
635
+ TREENODE_CACHE_LIMIT = 100
636
+ ```
637
+ **Automatic Management**: In most cases, users don’t need to manually manage cache operations.
638
+ **Manual Cache Clearing**:
639
+ - **Clear cache for a single model**: Use `clear_cache()` at the model level:
640
+ ```python
641
+ MyTreeNodeModel.clear_cache()
642
+ ```
643
+ - **Clear cache for all models**: Use the global `treenode_cache.clear()` method:
644
+ ```python
645
+ from treenode.cache import treenode_cache
646
+ treenode_cache.clear()
647
+ ```
648
+
649
+ ## **Export and Import Functionality**
650
+ ### **Overview**
651
+ TreeNode v2.0 includes **built-in export and import features** for easier data migration. Supported Formats: `csv`, `json`, `xlsx`, `yaml`, `tsv`
652
+ ### Installation for Import/Export Features
653
+ By default, import/export functionality is **not included** to keep the package lightweight. If you need these features, install the package with:
654
+ ```bash
655
+ pip install django-fast-treenode[import_export]
656
+ ```
657
+ Once installed, **import/export buttons will appear** in the Django admin interface.
658
+ ### **Important Considerations**
659
+ 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.
660
+
661
+ ## Migration Guide
662
+ #### Switching from `django-treenode`
663
+ 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.
664
+
665
+
666
+ #### Upgrading to `django-fast-treenode` 2.0
667
+ To upgrade to version 2.0, simply run:
668
+ ```bash
669
+ pip install --upgrade django-fast-treenode
670
+ ```
671
+ or
672
+ ```bash
673
+ pip install django-fast-treenode[import_export]
674
+ ```
675
+ After upgrading, ensure that your database schema is up to date by running:
676
+ ```bash
677
+ python manage.py makemigrations
678
+ python manage.py migrate
679
+ ```
680
+ This will apply any necessary database changes automatically.
547
681
 
548
- ## License
549
- Released under [MIT License](https://github.com/TimurKady/django-fast-treenode/blob/main/LICENSE).
682
+ ## To do
683
+ These improvements aim to enhance usability, performance, and maintainability for all users of `django-fast-treenode`:
684
+ * **Cache Algorithm Optimization**: Testing and integrating more advanced cache eviction strategies.
685
+ * **Drag-and-Drop UI Enhancements**: Adding intuitive drag-and-drop functionality for tree node management.
686
+ * to be happy, to don't worry, until die.
550
687
 
551
- ## Cautions
552
- The provided code is already being used in production projects, even though I have only done general testing. That is why the risk of using the code lies entirely with you.
688
+ Your wishes, objections, comments are welcome.
553
689
 
554
- **Warning**: don't access the tree node fields directly! Most of them have been removed as unnecessary. In the future, only `tn_parent` and `tn_priority` will be kept. Use the functions described in the documentation above or the documentation for the [original application](https://github.com/fabiocaccamo/django-treenode).
555
690
 
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)
691
+ # Django-fast-treenode
692
+ ## License
693
+ Released under [MIT License](https://github.com/TimurKady/django-fast-treenode/blob/main/LICENSE).
560
694
 
561
- Special thanks to [Mathieu Leplatre](https://blog.mathieu-leplatre.info/pages/about.html) for the advice used in writing this application
695
+ ## Cautions
696
+ **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.
562
697
 
563
- ## To do
564
- Future plans:
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.
698
+ **Risks of Direct Field Access:**
699
+ - **Database Integrity Issues**: Directly modifying fields may break tree integrity, causing inconsistent parent-child relationships.
700
+ - **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.
701
+ - **Unsupported Behavior**: Future versions may change field structures or remove unnecessary fields. Relying on them directly risks breaking compatibility.
568
702
 
703
+ Instead, always use the **documented methods** described above or refer to the [original application documentation](https://github.com/fabiocaccamo/django-treenode).
569
704
 
570
- Your wishes, objections, comments are welcome.
705
+ ## Credits
706
+ 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,27 +1,3 @@
1
- Metadata-Version: 2.1
2
- Name: django-fast-treenode
3
- Version: 1.1.2
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
16
- Classifier: Programming Language :: Python :: 3
17
- Classifier: Programming Language :: Python :: 3 :: Only
18
- Classifier: Programming Language :: Python :: 3.8
19
- Classifier: Programming Language :: Python :: 3.9
20
- Requires-Python: >=3.8
21
- Description-Content-Type: text/markdown
22
- License-File: LICENSE
23
- Requires-Dist: Django>=3.0
24
-
25
1
  # Django-fast-treenode
26
2
  __Combination of Adjacency List and Closure Table__
27
3
 
@@ -74,8 +50,7 @@ You can easily find additional information on your own on the Internet.
74
50
  4. Make your model-admin inherit from ```treenode.admin.TreeNodeModelAdmin``` (described below)
75
51
  5. Run python manage.py makemigrations and ```python manage.py migrate```
76
52
 
77
- When updating an existing project, simply call ```cls.update_tree()``` function once.
78
- 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).
79
54
 
80
55
  ## Configuration
81
56
  ### `models.py`
@@ -141,6 +116,8 @@ CACHES = {
141
116
  },
142
117
  "treenode": {
143
118
  "BACKEND": "django.core.cache.backends.locmem.LocMemCache",
119
+ "KEY_PREFIX": "", # This is important!
120
+ "VERSION": None, # This is important!
144
121
  },
145
122
  }
146
123
  ```
@@ -148,15 +125,42 @@ CACHES = {
148
125
 
149
126
  ```
150
127
  class YoursForm(TreeNodeForm):
151
-
152
- class Meta:
153
- widgets = {
154
- 'tn_parent': TreeWidget(attrs={'style': 'min-width:400px'}),
155
- }
128
+ # Your code is here
156
129
  ```
157
130
 
158
- ## Usage
131
+ ## Updating to django-fast-treenode 2.X
132
+ ### Overview
133
+ If you are upgrading from a previous version, you need to follow these steps to ensure compatibility and proper functionality.
134
+
135
+ ### Update Process
136
+ 1. **Upgrade the package**
137
+ Run the following command to install the latest version:
138
+
139
+ ```bash
140
+ pip install --upgrade django-fast-treenode
141
+ ```
142
+
143
+ 2. **Apply database migrations**
144
+ After upgrading, you need to apply the necessary database migrations:
145
+
146
+ ```bash
147
+ python manage.py makemigrations
148
+ python manage.py migrate
149
+ ```
150
+
151
+ 3. **Restart the application**
152
+ Finally, restart your Django application to apply all changes:
159
153
 
154
+ ```bash
155
+ python manage.py runserver
156
+ ```
157
+
158
+ **Important Notes**: Failing to apply migrations (`migrate`) after upgrading may lead to errors when interacting with tree nodes.
159
+
160
+ By following these steps, you will ensure a smooth transition to the latest version of django-fast-treenode without data inconsistencies.
161
+
162
+
163
+ ## Usage
160
164
  ### Methods/Properties
161
165
 
162
166
  - [`delete`](#delete)
@@ -211,11 +215,17 @@ class YoursForm(TreeNodeForm):
211
215
  - [`update_tree`](#update_tree)
212
216
 
213
217
  #### `delete`
214
- **Delete a node** if `cascade=True` (default behaviour), children and descendants will be deleted too,
215
- otherwise children's parent will be set to `None` (then children become roots):
218
+ **Delete a node** provides two deletion strategies:
219
+ - **Cascade Delete (`cascade=True`)**: Removes the node along with all its descendants.
220
+ - **Reparenting (`cascade=False`)**: Moves the children of the deleted node up one level in the hierarchy before removing the node itself.
221
+
216
222
  ```python
217
- obj.delete(cascade=True)
223
+ node.delete(cascade=True) # Deletes node and all its descendants
224
+ node.delete(cascade=False) # Moves children up and then deletes the node
218
225
  ```
226
+ This ensures greater flexibility in managing tree structures while preventing orphaned nodes.
227
+
228
+ ---
219
229
 
220
230
  #### `delete_tree`
221
231
  **Delete the whole tree** for the current node class:
@@ -337,6 +347,8 @@ obj.get_descendants_tree()
337
347
  obj.descendants_tree
338
348
  ```
339
349
 
350
+ **Important**: In future projects, avoid using `get_descendants_tree()`. It will be removed in the next version.
351
+
340
352
  #### `get_descendants_tree_display`
341
353
  Get a **multiline** `string` representing the **model tree**:
342
354
  ```python
@@ -345,6 +357,8 @@ obj.get_descendants_tree_display(include_self=False, depth=None)
345
357
  obj.descendants_tree_display
346
358
  ```
347
359
 
360
+ **Important**: In future projects, avoid using `get_descendants_tree_display()`. It will be removed in the next version.
361
+
348
362
  #### `get_first_child`
349
363
  Get the **first child node**:
350
364
  ```python
@@ -568,27 +582,83 @@ obj.is_sibling_of(target_obj)
568
582
  ```python
569
583
  cls.update_tree()
570
584
  ```
585
+ ## **Cache Management**
586
+ ### **Overview**
587
+ 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.
588
+
589
+ ### **Key Features**
590
+ **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`.
591
+ **settings.py**
592
+ ``` python
593
+ TREENODE_CACHE_LIMIT = 100
594
+ ```
595
+ **Automatic Management**: In most cases, users don’t need to manually manage cache operations.
596
+ **Manual Cache Clearing**:
597
+ - **Clear cache for a single model**: Use `clear_cache()` at the model level:
598
+ ```python
599
+ MyTreeNodeModel.clear_cache()
600
+ ```
601
+ - **Clear cache for all models**: Use the global `treenode_cache.clear()` method:
602
+ ```python
603
+ from treenode.cache import treenode_cache
604
+ treenode_cache.clear()
605
+ ```
606
+
607
+ ## **Export and Import Functionality**
608
+ ### **Overview**
609
+ TreeNode v2.0 includes **built-in export and import features** for easier data migration. Supported Formats: `csv`, `json`, `xlsx`, `yaml`, `tsv`
610
+ ### Installation for Import/Export Features
611
+ By default, import/export functionality is **not included** to keep the package lightweight. If you need these features, install the package with:
612
+ ```bash
613
+ pip install django-fast-treenode[import_export]
614
+ ```
615
+ Once installed, **import/export buttons will appear** in the Django admin interface.
616
+ ### **Important Considerations**
617
+ 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.
618
+
619
+ ## Migration Guide
620
+ #### Switching from `django-treenode`
621
+ 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.
622
+
623
+
624
+ #### Upgrading to `django-fast-treenode` 2.0
625
+ To upgrade to version 2.0, simply run:
626
+ ```bash
627
+ pip install --upgrade django-fast-treenode
628
+ ```
629
+ or
630
+ ```bash
631
+ pip install django-fast-treenode[import_export]
632
+ ```
633
+ After upgrading, ensure that your database schema is up to date by running:
634
+ ```bash
635
+ python manage.py makemigrations
636
+ python manage.py migrate
637
+ ```
638
+ This will apply any necessary database changes automatically.
571
639
 
572
- ## License
573
- Released under [MIT License](https://github.com/TimurKady/django-fast-treenode/blob/main/LICENSE).
640
+ ## To do
641
+ These improvements aim to enhance usability, performance, and maintainability for all users of `django-fast-treenode`:
642
+ * **Cache Algorithm Optimization**: Testing and integrating more advanced cache eviction strategies.
643
+ * **Drag-and-Drop UI Enhancements**: Adding intuitive drag-and-drop functionality for tree node management.
644
+ * to be happy, to don't worry, until die.
574
645
 
575
- ## Cautions
576
- The provided code is already being used in production projects, even though I have only done general testing. That is why the risk of using the code lies entirely with you.
646
+ Your wishes, objections, comments are welcome.
577
647
 
578
- **Warning**: don't access the tree node fields directly! Most of them have been removed as unnecessary. In the future, only `tn_parent` and `tn_priority` will be kept. Use the functions described in the documentation above or the documentation for the [original application](https://github.com/fabiocaccamo/django-treenode).
579
648
 
580
- ## Credits
581
- This software contains, uses, including in a modified form:
582
- * [django-treenode](https://github.com/fabiocaccamo/django-treenode) by [Fabio Caccamo](https://github.com/fabiocaccamo);
583
- * [Select2-to-Tree](https://github.com/clivezhg/select2-to-tree) Select2 extension by [clivezhg](https://github.com/clivezhg)
649
+ # Django-fast-treenode
650
+ ## License
651
+ Released under [MIT License](https://github.com/TimurKady/django-fast-treenode/blob/main/LICENSE).
584
652
 
585
- Special thanks to [Mathieu Leplatre](https://blog.mathieu-leplatre.info/pages/about.html) for the advice used in writing this application
653
+ ## Cautions
654
+ **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.
586
655
 
587
- ## To do
588
- Future plans:
589
- * may be will add the ability to determine the priority of the parent by any field, for example, by creation date or alphabetical order;
590
- * drug-and-drop support;
591
- * to be happy, to don't worry, until die.
656
+ **Risks of Direct Field Access:**
657
+ - **Database Integrity Issues**: Directly modifying fields may break tree integrity, causing inconsistent parent-child relationships.
658
+ - **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.
659
+ - **Unsupported Behavior**: Future versions may change field structures or remove unnecessary fields. Relying on them directly risks breaking compatibility.
592
660
 
661
+ Instead, always use the **documented methods** described above or refer to the [original application documentation](https://github.com/fabiocaccamo/django-treenode).
593
662
 
594
- Your wishes, objections, comments are welcome.
663
+ ## Credits
664
+ 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.