A simple and lightweight implementation of materialized path tree structures in Django.
Project description
Django Materialized Paths
A simple and lightweight implementation of materialized path tree structures in Django.
Installation
To install, run:
pip install django-materialized-paths
Configuration
Add the following into the INSTALLED_APPS of your projects:
INSTALLED_APPS = (
...
'django-materialized-paths',
)
Usage
To use, extend the BaseNode into your model:
from django-materialized-paths import BaseNode
class FolderExample(BaseNode):
"""My folder class"""
name = models.CharField(max_length=48)
The model overrides Django's django.db.models.Model save() method to automatically manage changes to inheritance:
from .models import FolderExample # concrete class from above
root = FolderExample.objects.create(name="root")
child = FolderExample.objects.create(name="child", parent=root)
grandchild = FolderExample.objects.create(name="child", parent=child)
For example, to convert grandchild to a root:
grandchild.parent = None
grandchild.save()
Usage - Properties and Inherited
BaseNode.depth # Root is 0
BaseNode.parent
BaseNode.children # Only returns direct descendants
BaseNode.save() # Set the parent field to automatically manage hierarchy
BaseNode.delete() # NOTE: The BaseNode.parent field is set to cascade, so deleting a parent will delete all children
Usage - Methods
Note that these methods generally return querysets
# Accessors
BaseNode.get_root()
BaseNode.get_ancestor(depth=int)
BaseNode.get_ancestors()
BaseNode.get_descendants()
BaseNode.get_siblings()
# Convenience
BaseNode.has_children()
BaseNode.is_child_of(parent_id=int)
# ID-based accessors - computed directly from path without accessing db
BaseNode.get_ancestors_ids()
BaseNode.get_descendants_ids()
Authors
- Cameron McNierney - Original author - https://github.com/cmcnierney
License
This project is licensed under the MIT License - see the LICENSE.md file for details
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django-materialized-paths-0.1.tar.gz.
File metadata
- Download URL: django-materialized-paths-0.1.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
97593081e6dbf410e6aa9c7548caa0d2919f721eeaf6ae6b37f65cf6602e144c
|
|
| MD5 |
c42af4ec7eca7ff7beea1300cb1117ee
|
|
| BLAKE2b-256 |
5d58d2b1a7f5d51dad9478fbe90e6d462b592c8efe14230fbba4aaea5c3850fd
|
File details
Details for the file django_materialized_paths-0.1-py3-none-any.whl.
File metadata
- Download URL: django_materialized_paths-0.1-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4a152d35e8cc8c5fd7a337040d871d83c585ae41967b8ef368be6fcc0ed9bcc3
|
|
| MD5 |
d9d30fa3f87f7846e4445491e37c2fe9
|
|
| BLAKE2b-256 |
47309dff2c890af3f9819387aafdb148a57c8a76a01a22a597cda1467ad695f6
|