django-fast-treenode 1.1.3__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.3/README.md → django_fast_treenode-2.0.0/PKG-INFO +163 -27
  2. django_fast_treenode-1.1.3/django_fast_treenode.egg-info/PKG-INFO → django_fast_treenode-2.0.0/README.md +121 -53
  3. django_fast_treenode-1.1.3/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.3 → django_fast_treenode-2.0.0}/setup.cfg +14 -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.3/PKG-INFO → django_fast_treenode-2.0.0/treenode/docs/Documentation +121 -53
  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.3/django_fast_treenode.egg-info/SOURCES.txt +0 -39
  39. django_fast_treenode-1.1.3/django_fast_treenode.egg-info/requires.txt +0 -1
  40. django_fast_treenode-1.1.3/pyproject.toml +0 -3
  41. django_fast_treenode-1.1.3/treenode/__init__.py +0 -7
  42. django_fast_treenode-1.1.3/treenode/admin.py +0 -136
  43. django_fast_treenode-1.1.3/treenode/apps.py +0 -6
  44. django_fast_treenode-1.1.3/treenode/compat.py +0 -8
  45. django_fast_treenode-1.1.3/treenode/factory.py +0 -68
  46. django_fast_treenode-1.1.3/treenode/forms.py +0 -32
  47. django_fast_treenode-1.1.3/treenode/managers.py +0 -69
  48. django_fast_treenode-1.1.3/treenode/models.py +0 -668
  49. django_fast_treenode-1.1.3/treenode/static/select2tree/select2tree.css +0 -176
  50. django_fast_treenode-1.1.3/treenode/static/select2tree/select2tree.js +0 -181
  51. django_fast_treenode-1.1.3/treenode/static/treenode/css/treenode.css +0 -85
  52. django_fast_treenode-1.1.3/treenode/static/treenode/js/treenode.js +0 -201
  53. django_fast_treenode-1.1.3/treenode/templates/.gitkeep +0 -1
  54. django_fast_treenode-1.1.3/treenode/templates/widgets/.gitkeep +0 -1
  55. django_fast_treenode-1.1.3/treenode/templates/widgets/attrs.html +0 -7
  56. django_fast_treenode-1.1.3/treenode/templates/widgets/options.html +0 -1
  57. django_fast_treenode-1.1.3/treenode/templates/widgets/select2tree.html +0 -22
  58. django_fast_treenode-1.1.3/treenode/tests.py +0 -3
  59. django_fast_treenode-1.1.3/treenode/version.py +0 -3
  60. django_fast_treenode-1.1.3/treenode/views.py +0 -3
  61. django_fast_treenode-1.1.3/treenode/widgets.py +0 -43
  62. {django_fast_treenode-1.1.3 → django_fast_treenode-2.0.0}/LICENSE +0 -0
  63. {django_fast_treenode-1.1.3 → django_fast_treenode-2.0.0}/MANIFEST.in +0 -0
  64. {django_fast_treenode-1.1.3 → django_fast_treenode-2.0.0}/django_fast_treenode.egg-info/dependency_links.txt +0 -0
  65. {django_fast_treenode-1.1.3 → django_fast_treenode-2.0.0}/django_fast_treenode.egg-info/top_level.txt +0 -0
  66. {django_fast_treenode-1.1.3 → django_fast_treenode-2.0.0}/setup.py +0 -0
  67. /django_fast_treenode-1.1.3/treenode/static/.gitkeep → /django_fast_treenode-2.0.0/treenode/__init__.py +0 -0
  68. {django_fast_treenode-1.1.3/treenode/docs → django_fast_treenode-2.0.0/treenode/static/treenode}/.gitkeep +0 -0
  69. {django_fast_treenode-1.1.3/treenode/static/select2tree → django_fast_treenode-2.0.0/treenode/static/treenode/css}/.gitkeep +0 -0
  70. {django_fast_treenode-1.1.3/treenode/static/treenode → django_fast_treenode-2.0.0/treenode/static/treenode/js}/.gitkeep +0 -0
  71. {django_fast_treenode-1.1.3/treenode/static/treenode/css → django_fast_treenode-2.0.0/treenode/templates}/.gitkeep +0 -0
  72. {django_fast_treenode-1.1.3/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,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
- When updating an existing project, simply call ```cls.update_tree()``` function once.
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,42 @@ 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
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:
161
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
162
164
  ### Methods/Properties
163
165
 
164
166
  - [`delete`](#delete)
@@ -213,11 +215,17 @@ class YoursForm(TreeNodeForm):
213
215
  - [`update_tree`](#update_tree)
214
216
 
215
217
  #### `delete`
216
- **Delete a node** if `cascade=True` (default behaviour), children and descendants will be deleted too,
217
- 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
+
218
222
  ```python
219
- 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
220
225
  ```
226
+ This ensures greater flexibility in managing tree structures while preventing orphaned nodes.
227
+
228
+ ---
221
229
 
222
230
  #### `delete_tree`
223
231
  **Delete the whole tree** for the current node class:
@@ -339,6 +347,8 @@ obj.get_descendants_tree()
339
347
  obj.descendants_tree
340
348
  ```
341
349
 
350
+ **Important**: In future projects, avoid using `get_descendants_tree()`. It will be removed in the next version.
351
+
342
352
  #### `get_descendants_tree_display`
343
353
  Get a **multiline** `string` representing the **model tree**:
344
354
  ```python
@@ -347,6 +357,8 @@ obj.get_descendants_tree_display(include_self=False, depth=None)
347
357
  obj.descendants_tree_display
348
358
  ```
349
359
 
360
+ **Important**: In future projects, avoid using `get_descendants_tree_display()`. It will be removed in the next version.
361
+
350
362
  #### `get_first_child`
351
363
  Get the **first child node**:
352
364
  ```python
@@ -570,27 +582,83 @@ obj.is_sibling_of(target_obj)
570
582
  ```python
571
583
  cls.update_tree()
572
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.
573
639
 
574
- ## License
575
- 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.
576
645
 
577
- ## Cautions
578
- 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.
579
647
 
580
- **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).
581
648
 
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)
649
+ # Django-fast-treenode
650
+ ## License
651
+ Released under [MIT License](https://github.com/TimurKady/django-fast-treenode/blob/main/LICENSE).
586
652
 
587
- 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.
588
655
 
589
- ## To do
590
- Future plans:
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.
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.
594
660
 
661
+ Instead, always use the **documented methods** described above or refer to the [original application documentation](https://github.com/fabiocaccamo/django-treenode).
595
662
 
596
- 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.