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.11 or better, Python 2.7 and 3.4 or better.

Features and limitations

  • Supports only integer primary keys.

  • Allows adding an integer field to order nodes on a given level.

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

  • Only supports 10 levels of nodes on MariaDB.

  • Only supports maximum primary key values of 16^9 on sqlite3 and MariaDB (this may change if the database engines implement proper array support).

  • 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. The first field is always an integer, the other fields are lists of integers.

  • 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.

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.

  • 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.2.0.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

django_tree_queries-0.2.0-py2.py3-none-any.whl (10.8 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

  • Download URL: django-tree-queries-0.2.0.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/2.7.15rc1

File hashes

Hashes for django-tree-queries-0.2.0.tar.gz
Algorithm Hash digest
SHA256 f74bd2e830180f3ad4433d3cb63780ac9ddb64549f2927599d661c5e3f87be29
MD5 2963269369b73189f04d5a6fd8b23dd4
BLAKE2b-256 f487548904c5009da97c19998254126f8f9544fe059df1d56fc8d002108daec0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: django_tree_queries-0.2.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 10.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/2.7.15rc1

File hashes

Hashes for django_tree_queries-0.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 4dafd55be308a1615940dec638ca766a2f3268a89d3a6bf3703f128a612566cb
MD5 7b5e9309a6a8cdd280c3a1869d23617c
BLAKE2b-256 b1e32738f1e7af80d091d8c020b3264c41cd48434f9f4b470789ec6b6fdc7e73

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