Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
  • Loading branch information
baseplate-admin committed Feb 22, 2024
1 parent a5bc477 commit 28cd659
Show file tree
Hide file tree
Showing 10 changed files with 161 additions and 98 deletions.
56 changes: 0 additions & 56 deletions .travis.yml

This file was deleted.

31 changes: 20 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,36 @@ using the native Postgres extension `ltree`.
Postgresql has already a optimized and very useful tree implementation for data.
The extension is [ltree](https://www.postgresql.org/docs/9.6/static/ltree.html)

This fork contains a backport to Django 1.11 and Python 3.6.
This fork contains is a continuation of the work done by [`mariocesar`](https://github.com/mariocesar/) on [`django-ltree`](https://github.com/mariocesar/django-ltree).

<!--
[![Test](https://github.com/mariocesar/django-ltree/actions/workflows/test.yml/badge.svg)](https://github.com/mariocesar/django-ltree/actions/workflows/test.yml)

-->

## Links

- Pypi https://pypi.org/project/django-ltree/
- Source code https://github.com/mariocesar/django-ltree
- Bugs https://github.com/mariocesar/django-ltree/issues
- Contribute https://github.com/mariocesar/django-ltree/pulls
- Documentation `TODO`
- Pypi https://pypi.org/project/django-ltree/
- Source code https://github.com/mariocesar/django-ltree
- Bugs https://github.com/mariocesar/django-ltree/issues
- Contribute https://github.com/mariocesar/django-ltree/pulls
- Documentation `TODO`

## Install

```
```py
pip install django-ltree
```

Then add `django_ltree` to `INSTALLED_APPS` in your Django project settings.

```python
INSTALLED_APPS = [
...,
'django_ltree',
...
]
```

And make sure to run `django_ltree` migrations before you added the `PathField`

```
Expand All @@ -38,7 +47,7 @@ python manage.py migrate django_ltree
You can alternatively specify the `django_ltree` dependency in the migrations of
your applications that requires `PathField`, and run migrations smoothly.

```
```python
class Migration(migrations.Migration):
dependencies = [
('django_ltree', '__latest__'),
Expand All @@ -47,8 +56,8 @@ class Migration(migrations.Migration):

## Requires

- Django 1.11 or superior
- Python 2
- Django 5.0 or superior
- Python 3.10 or higher

## Testing

Expand Down
2 changes: 1 addition & 1 deletion django_ltree/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,4 @@ def get_db_prep_value(self, value, connection, prepared=False):
elif isinstance(value, (list, str)):
return str(PathValue(value))

raise ValueError("Unknown value type {}".format(type(value)))
raise ValueError(f"Unknown value type {type(value)}")
4 changes: 2 additions & 2 deletions django_ltree/lookups.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class SimpleLookup(Lookup):
def as_sql(self, compiler, connection):
lhs, lhs_params = self.process_lhs(compiler, connection)
rhs, rhs_params = self.process_rhs(compiler, connection)
return "{} {} {}".format(lhs, self.lookup_operator, rhs), [
return f"{lhs} {self.lookup_operator} {rhs}", [
*lhs_params,
*rhs_params,
]
Expand All @@ -22,7 +22,7 @@ class EqualLookup(Lookup):
def as_sql(self, compiler, connection):
lhs, lhs_params = self.process_lhs(compiler, connection)
rhs, rhs_params = self.process_rhs(compiler, connection)
return "{} = {}".format(lhs, rhs), [*lhs_params, *rhs_params]
return f"{lhs} = {rhs}", [*lhs_params, *rhs_params]


@PathField.register_lookup
Expand Down
6 changes: 2 additions & 4 deletions django_ltree/migrations/0001_create_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
class Migration(migrations.Migration):
initial = True

dependencies = [
]
dependencies = []

operations = [
migrations.RunSQL(
"CREATE EXTENSION IF NOT EXISTS ltree;",
"DROP EXTENSION ltree;"
"CREATE EXTENSION IF NOT EXISTS ltree;", "DROP EXTENSION ltree;"
)
]
11 changes: 4 additions & 7 deletions django_ltree/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.db import models
from typing import Any

from .fields import PathField, PathValue
from .managers import TreeManager
Expand All @@ -15,12 +16,8 @@ class Meta:
def label(self):
return self.path[-1]

def get_ancestors_paths(self): # type: () -> List[List[str]]
return [
PathValue(self.path[:n])
for n, p in enumerate(self.path)
if n > 0
]
def get_ancestors_paths(self) -> list[list[str]]:
return [PathValue(self.path[:n]) for n, p in enumerate(self.path) if n > 0]

def ancestors(self):
return type(self)._default_manager.filter(path__ancestors=self.path)
Expand All @@ -44,7 +41,7 @@ def siblings(self):
.exclude(path=self.path)
)

def add_child(self, slug, **kwargs): # type:(str) -> Any
def add_child(self, slug: str, **kwargs) -> Any:
assert "path" not in kwargs
kwargs["path"] = self.path[:]
kwargs["path"].append(slug)
Expand Down
132 changes: 131 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ django = ">=5.0.2"

[tool.poetry.group.dev.dependencies]
pytest = "^8.0.1"
tox = "^4.13.0"

[build-system]
requires = ["poetry-core"]
Expand Down
4 changes: 0 additions & 4 deletions python-versions.txt

This file was deleted.

12 changes: 0 additions & 12 deletions setup.cfg

This file was deleted.

0 comments on commit 28cd659

Please sign in to comment.