Skip to main content

Tree queries with explicit opt-in, without configurability

Project description

https://travis-ci.org/matthiask/django-tree-queries.svg?branch=master

Query Django model trees using adjacency lists and recursive common table expressions. Supports PostgreSQL, sqlite3 (3.8.3 or higher) and MariaDB (10.2.2 or higher), maybe also MySQL 8.0 but I found no easy way to test against it.

Supports Django 1.8, 1.11 or better, Python 2.7 and 3.4 or better. See the Travis CI build for more details.

Features and limitations

  • Supports only integer primary keys.

  • Allows specifying ordering among siblings.

  • Uses the correct definition of depth, where root nodes have a depth of zero.

  • The parent foreign key must be named "parent" at the moment (but why would you want to name it differently?)

  • The fields added by the common table expression always are tree_depth, tree_path and tree_ordering. The names cannot be changed. tree_depth is an integer, tree_path an array of primary keys and tree_ordering an array of values used for ordering nodes within their siblings.

  • Besides adding the fields mentioned above the package only adds queryset methods for filtering ancestors and descendants. Other features may be useful, but will not be added to the package just because it’s possible to do so.

  • Little code, and relatively simple when compared to other tree management solutions for Django. No redundant values so the only way to end up with corrupt data is by introducing a loop in the tree structure (making it a graph). The TreeNode abstract model class has some protection against this.

Usage

  • Install django-tree-queries using pip.

  • Extend tree_queries.models.TreeNode or build your own queryset and/or manager using tree_queries.query.TreeQuerySet. The TreeNode abstract model already contains a parent foreign key for your convenience and also uses model validation to protect against loops.

  • Call the with_tree_fields() queryset method if you require the additional fields respectively the CTE.

  • Until documentation is more complete I’ll have to refer you to the test suite for additional instructions and usage examples.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-tree-queries-0.3.3.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

django_tree_queries-0.3.3-py2.py3-none-any.whl (11.1 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django-tree-queries-0.3.3.tar.gz.

File metadata

  • Download URL: django-tree-queries-0.3.3.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/3.6.7

File hashes

Hashes for django-tree-queries-0.3.3.tar.gz
Algorithm Hash digest
SHA256 6680031216693e2a89dcbd7ec79d92f334b2e138ae6c1ef5d5486413fab5712e
MD5 e5d503d8ba3adda379269b21345c5b3a
BLAKE2b-256 fb5ef9d2331f6f2574fda344294fcc9a7b5d46197f72e2d9a1c375b888e964d3

See more details on using hashes here.

File details

Details for the file django_tree_queries-0.3.3-py2.py3-none-any.whl.

File metadata

  • Download URL: django_tree_queries-0.3.3-py2.py3-none-any.whl
  • Upload date:
  • Size: 11.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/3.6.7

File hashes

Hashes for django_tree_queries-0.3.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 0e9d89b66b12ffdb1ef4668bcd7bec1bb401323e681ead492d97077833f477bd
MD5 42190163ed5212c7bb9e9e794c125246
BLAKE2b-256 c8fe8b3d419c378682b4edffd396202a96ab286ce487c0a5bc09d2af85b6b996

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page