Metadata-Version: 2.2
Name: django-fast-treenode
Version: 2.1.4
Summary: Application for supporting tree (hierarchical) data structure in Django projects
Home-page: https://django-fast-treenode.readthedocs.io/
Author: Timur Kady
Author-email: Timur Kady <timurkady@yandex.com>
License: MIT License
        
        Copyright (c) 2020-2025 Timur Kady
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/TimurKady/django-fast-treenode
Project-URL: Documentation, https://django-fast-treenode.readthedocs.io/
Project-URL: Source, https://github.com/TimurKady/django-fast-treenode
Project-URL: Issues, https://github.com/TimurKady/django-fast-treenode/issues
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Framework :: Django
Classifier: Framework :: Django :: 4.0
Classifier: Framework :: Django :: 4.1
Classifier: Framework :: Django :: 4.2
Classifier: Framework :: Django :: 5.0
Classifier: Framework :: Django :: 5.1
Classifier: Framework :: Django :: 5.2
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: Django>=4.0
Requires-Dist: pympler>=1.0
Requires-Dist: django-widget-tweaks>=1.5
Requires-Dist: msgpack>=1.1
Provides-Extra: import-export
Requires-Dist: openpyxl; extra == "import-export"
Requires-Dist: pyyaml; extra == "import-export"
Requires-Dist: xlsxwriter; extra == "import-export"

# Django-fast-treenode 
**Hybrid Tree Storage**

[![Tests](https://github.com/TimurKady/django-fast-treenode/actions/workflows/test.yaml/badge.svg?branch=main)](https://github.com/TimurKady/django-fast-treenode/actions/workflows/test.yaml)
[![Docs](https://readthedocs.org/projects/django-fast-treenode/badge/?version=latest)](https://django-fast-treenode.readthedocs.io/)
[![PyPI](https://img.shields.io/pypi/v/django-fast-treenode.svg)](https://pypi.org/project/django-fast-treenode/)
[![Published on Django Packages](https://img.shields.io/badge/Published%20on-Django%20Packages-0c3c26)](https://djangopackages.org/packages/p/django-fast-treenode/)
[![Sponsor](https://img.shields.io/github/sponsors/TimurKady)](https://github.com/sponsors/TimurKady)

**Django Fast TreeNode** is a high-performance Django application for working with tree structures. 

## Features
- **Hybrid storage model**: Combines Adjacency List and Materialized Path (versions 2.2 and above) Closure Table (versions 2.1 and earlier) for optimal performance.
- **Custom caching system**: A built-in caching mechanism, specifically designed for this package, significantly boosts execution speed.
- **Efficient queries**: Retrieve ancestors, descendants, breadcrumbs, and tree depth with only one SQL queriy.
- **Bulk operations**: Supports fast insertion, movement, and deletion of nodes.
- **Flexibility**: Fully integrates with Django ORM and adapts to various business logic needs.
- **Admin panel integration**: Full compatibility with Django's admin panel, allowing intuitive management of tree structures.
- **Import & Export functionality**: Built-in support for importing and exporting tree structures in multiple formats (CSV, JSON, XLSX, YAML, TSV), including integration with the Django admin panel.

It seems that django-fast-treenode is currently the most balanced and performant solution for most tasks, especially those related to dynamic hierarchical data structures. Check out the results of (comparison tests)[#] with other Django packages.

## Use Cases
Django Fast TreeNode is suitable for a wide range of applications, from simple directories to complex systems with deep hierarchical structures:
- **Categories and taxonomies**: Manage product categories, tags, and classification systems.
- **Menus and navigation**: Create tree-like menus and nested navigation structures.
- **Forums and comments**: Store threaded discussions and nested comment chains.
- **Geographical data**: Represent administrative divisions, regions, and areas of influence.
- **Organizational and Business Structures**: Model company hierarchies, business processes, employees and departments.

In all applications, `django-fast-treenode` models show excellent performance and stability.

## Quick start
1. Run `pip install django-fast-treenode`.
2. Add `treenode` to `settings.INSTALLED_APPS`.

```python
INSTALLED_APPS = [
    ...
    'treenode',
]
```

3. Define your model inherit from `treenode.models.TreeNodeModel`.

```python
from treenode.models import TreeNodeModel

class Category(TreeNodeModel):
    name = models.CharField(max_length=255)
    treenode_display_field = "name"
```

4. Make your model-admin inherit from `treenode.admin.TreeNodeModelAdmin`.

```python
from treenode.admin import TreeNodeModelAdmin
from .models import Category

@admin.register(Category)
class CategoryAdmin(TreeNodeModelAdmin):
    list_display = ("name",)
    search_fields = ("name",)
```
5. Run migrations.

```bash 
python manage.py makemigrations
python manage.py migrate
```

6. Run server and use!

```bash
>>> root = Category.objects.create(name="Root")
>>> child = Category.objects.create(name="Child")
>>> child.set_parent(root)
>>> root_descendants_list = root.get_descendants()
>>> root_children_queryset = root.get_children_queryset()
>>> ancestors_pks = child.get_ancestors_pks()
```

## Documentation
Full documentation is available at **[ReadTheDocs](https://django-fast-treenode.readthedocs.io/)**.

Quick access links:
* [Installation, configuration and fine tuning](https://django-fast-treenode.readthedocs.io/installation/)
* [Model Inheritance and Extensions](https://django-fast-treenode.readthedocs.io/models/)
* [Working with Admin Classes](https://django-fast-treenode.readthedocs.io/admin/)
* [API Reference](https://django-fast-treenode.readthedocs.io/api/)
* [Import & Export](https://django-fast-treenode.readthedocs.io/import_export/)
* [Caching and working with cache](https://django-fast-treenode.readthedocs.io/cache/)
* [Migration and upgrade guide](https://django-fast-treenode.readthedocs.io/migration/)

Your wishes, objections, comments are welcome.

## License
Released under [MIT License](https://github.com/TimurKady/django-fast-treenode/blob/main/LICENSE).

## Credits
Thanks to everyone who contributed to the development and testing of this package, as well as the Django community for their inspiration and support. 

Special thanks to [Fabio Caccamo](https://github.com/fabiocaccamo) for the idea behind creating a fast Django application for handling hierarchies.
