Skip to main content

LTreeField for Django

Project description

https://badge.fury.io/py/django-ltree-field.svg https://codecov.io/gh/john-parton/django-ltree-field/branch/master/graph/badge.svg

Minimalist Django Field for the PostgreSQL ltree Type.

django-ltree-field attempts to make very few assumptions about your use case.

For a higher level API based on django-ltree-field, consider using a prebuilt model from django-ltree-utils.

It should be possible to re-implement the django-treebeard API, allowing for drop-in compatibility, but that is not a specific goal at this time. If someone starts this, let me know and I will provide some assistance.

Documentation

The full documentation is at https://django-ltree-field.readthedocs.io.

Quickstart

Install PostgreSQL LTreeField for Django:

pip install django-ltree-field

Add it to your INSTALLED_APPS:

INSTALLED_APPS = (
    ...
    'django_ltree_field',
    ...
)

Add an LTreeField to a new or existing model:

from django_ltree_field.fields import LTreeField

class SimpleNode(models.Model):
    path = LTreeField(index=True, unique=True)

    class Meta:
        ordering = ['path']

Features

  • Implements only the bare minimum to make the ltree PostgreSQL type usable

  • LTreeField accepts a string of dotted labels, or a list of labels

  • The ltree type is adapted to a Python list

  • Relatively complete set of lookups and transforms.

Non-Features

  • Does not implement an abstract “Node” model which has a nicer API (See django-ltree-utils for ready-made classes and managers)

  • Does virtually no sanity checking. You can insert nodes without roots, and generally put the tree in a bad state

  • PostgreSQL compatibility only

Future Features

I will happily accept minimal features required to make the field be reasonably usable. In particular, every operator, function, and example on the official PostgreSQL docs should be implemented with Django’s ORM, with no RawSQL or non-idiomatic code.

Higher-level or richer features should be contributed to django-ltree-utils. As a rule of thumb, if an operation requires referencing more than one row at a time, or maintaining some more complicated state, it probably belongs there.

Running Tests

You need to have a reasonably updated version of PostgreSQL listening on port 5444. You can use docker-compose to start a server

docker-compose up

Does the code actually work?

source <YOURVIRTUALENV>/bin/activate
(myenv) $ pip install -r requirements.txt -r requirements_test.txt --upgrade
(myenv) $ ./runtests.py

History

0.1.5

  • CI/CD with Github Actions

  • Updated docs

0.1.0 (2021-03-24)

  • First release on PyPI.

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-ltree-field-0.1.7.tar.gz (24.9 kB view details)

Uploaded Source

Built Distribution

django_ltree_field-0.1.7-py2.py3-none-any.whl (12.7 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django-ltree-field-0.1.7.tar.gz.

File metadata

  • Download URL: django-ltree-field-0.1.7.tar.gz
  • Upload date:
  • Size: 24.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.9.6

File hashes

Hashes for django-ltree-field-0.1.7.tar.gz
Algorithm Hash digest
SHA256 b2f4df841498a5e9edf0953e205e6ec29946dd8f2a0ec7accfd34cd81f62fa3e
MD5 51670126dae3af8864f1c6ff872210cc
BLAKE2b-256 d8d8bf803ed06d5eda5366d6680f1d291634b3fbab8112df37bbbaf0bc37540f

See more details on using hashes here.

File details

Details for the file django_ltree_field-0.1.7-py2.py3-none-any.whl.

File metadata

  • Download URL: django_ltree_field-0.1.7-py2.py3-none-any.whl
  • Upload date:
  • Size: 12.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.9.6

File hashes

Hashes for django_ltree_field-0.1.7-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 2649331536ffb1ca374275cccb816feda833ddebe216e255e8dba60ea47b6c48
MD5 993c620e7f7383379bf731b8e8b2b9da
BLAKE2b-256 deee3f59b293020a255c80fe59fbb5833e68c6dc05dfc11c30e1128c578cc93a

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