django-tree-materialized 0.0.6

Creator: codyrutscher

Last updated:

Add to Cart

Description:

djangotreematerialized 0.0.6

Requirements

Python 3.6+
A supported version of Django (currently 3.x)



Getting It
You can get Django tree materialized by using pip:
$ pip install django-tree-materialized
If you want to install it from source, grab the git repository from GitHub and run setup.py:
$ git clone git://github.com/kostya-ten/django_tree_materialized.git
$ cd django_tree_materialized
$ python setup.py install


Installation
To enable django_tree_materialized in your project you need to add it to INSTALLED_APPS in your projects settings.py
INSTALLED_APPS = (
# ...
'django_tree_materialized',
# ...
)


Using
Add to your models.py
from django_tree_materialized.models import MPTree

class YouModel(MPTree):
name = models.CharField(max_length=200)
Simple example
name = models.YouModel.create(name="Name name")
sub = models.YouModel.create(name="Name node2", parent=name)

# Get a list of parents
result = name.get_family() # Return QuerySet object
for item in result:
print(item.id, item.name, item.level, item.path, item.parent)


Method
get_family() - Get a list of parents
get_parent() - Return parent
get_root() - Return root object
move() - Moves one node to another
Move
name = models.YouModel.create(name="Name name")
new_name = models.YouModel.create(name="Name node2")

result = name.move(new_name) # Return QuerySet new_name object

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Customer Reviews

There are no reviews.