Skip to main content

Django application for creating the tree structure in the model (very fast structure).

To create a new item in the tree need only choose a parent. The key (id) for the new item will be calculated automatically. You can get a list of the parents and the range of children without a database query.

Implemented to create a new item, delete the item, transfer item to the other parent (and the transfer of the group).

Description of the algorithm for constructing the tree can be found habr.ru or in the wiki (in Russian)

This app is available on PyPI.

Requirements

Supports Django 1.8 and later on Python 2.7, 3.2 - 3.5.

Works only with PostgreSQL 9.1 and later!

Installation

Clone this repository. The is an example of a project (app myapp use treensl)

Change the settings for connecting to the correct PostgreSQL DB.

or:

  1. pip install django-treensl

  2. Add app treensl in settings.py

  3. Create a new class of models from Tree32Abstract or Tree64Abstract (from treensl.models). Add your field in the model (for their fields, do not use the following names: id, parent_id, lvl, created_children, removed_children, holes). If necessary, change the dimension of the default tree (properties LEVELS and CHILDREN). For example see myapp/models.py

  4. Run python manage.py makemigrations

  5. The new file migration, add the 3 lines as in the example file myapp/migrations/0001_initial.py (the rows are marked with comments # add after makemigrations)

Possible dimensions of the tree

Before executing the migrate you can adjust the settings tree. The dimension of the tree depends on the length integer.

Recommended values (in the format LEVELS/CHILDREN/ROOT_ID):

  1. For int32: 3/1623/-2147483648, 4/255/-2147483648, 5/83/-2147483648, 6/39/-2147483648

  2. For int64: 3/2642243/-9223372036854775808, 4/65535/-9223372036854775808, 5/7129/-9223372036854775808, 6/1623/-9223372036854775808, 7/563/-9223372036854775808, 8/255/-9223372036854775808, 9/137/-9223372036854775808, 10/83/-9223372036854775808

Start usage

Run python manage.py migrate

Now, to create a new item in the tree need only choose a parent. The key (id) for the new item will be calculated automatically.

You can get a list of the parents and the range of children without a database query.

For any id call functions from the treensl.calc_values:

  1. parents_list(id, LEVELS, CHILDREN, ROOT_ID) - returns a list of the first to the last parent

  2. children_range(id, LEVELS, CHILDREN, ROOT_ID)- returns a list of the range of children

LEVELS, CHILDREN, ROOT_ID - settings current tree

Metadata

Release files for django-treensl 0.2.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-treensl 0.2.6
File Size Uploaded
django-treensl-0.2.6.tar.gz 12.6 kB Details

Release files / django-treensl-0.2.6.tar.gz

Download URL django-treensl-0.2.6.tar.gz
Size 12.6 kB
Tags Source
SHA-256 checksum
How to use checksums
d258b91941dbdae4311d1cda107bfe5f16926efc2586542ef85dabf6a3d1e913
BLAKE2b-256 checksum
How to use checksums
b8d02716eeae656975c07b2f853bffc288663f835f6e96a1304d12cb6c78ab02
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.2.6 This release

1 release file

0.2.5

1 release file

0.2.4

1 release file

0.2.3

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.1.17

1 release file

0.1.16

1 release file

0.1.15

1 release file

0.1.14

1 release file

0.1.13

1 release file

0.1.12

1 release file

0.1.11

1 release file

0.1.10

1 release file

0.1.9

1 release file

0.1.8

1 release file

0.1.7

1 release file

0.1.5

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page