Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
  • Loading branch information
baseplate-admin committed Feb 24, 2024
1 parent a6c5c9a commit 3df394c
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 4 deletions.
4 changes: 4 additions & 0 deletions django_ltree/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,24 @@
class TreeManager(models.Manager):
def get_queryset(self) -> TreeQuerySet["TreeModel"]:
"""Returns a queryset with the models ordered by `path`"""

return TreeQuerySet(model=self.model, using=self._db).order_by("path")

def roots(self) -> TreeQuerySet["TreeModel"]:
"""Returns the roots of a given model"""

return self.filter().roots()

def children(self, path: str) -> TreeQuerySet["TreeModel"]:
"""Returns the childrens of a given object"""

return self.filter().children(path)

def create_child(
self, parent: "TreeModel" = None, **kwargs
) -> TreeQuerySet["TreeModel"]:
"""Creates a tree child with or without parent"""

paths_in_use = parent.children() if parent else self.roots()
prefix = parent.path if parent else None
path_generator = PathGenerator(
Expand Down
4 changes: 1 addition & 3 deletions django_ltree/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


class PathGenerator(object):
def __init__(self, prefix=None, skip=None):
def __init__(self, prefix: str = None, skip: list[str] = None):
combinations = string.digits + string.ascii_letters

self.skip_paths = [] if skip is None else skip[:]
Expand Down Expand Up @@ -54,5 +54,3 @@ def guess_the_label_size(path_size: int, combination_size: int) -> int:
label_size += 1

return label_size


Empty file added django_ltree/py.typed
Empty file.
86 changes: 85 additions & 1 deletion poetry.lock

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

12 changes: 12 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ furo = "^2024.1.29"
myst-parser = "^2.0.0"
sphinx-reload = "^0.2.0"


[tool.poetry.group.dev.dependencies]
ruff = "^0.2.2"
mypy = "^1.8.0"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.mypy]
mypy_path = "./django_ltree/"
namespace_packages = false
show_error_codes = true
strict = true
warn_unreachable = true

0 comments on commit 3df394c

Please sign in to comment.