Skip to content

Commit

Permalink
Improve documentation on indexing
Browse files Browse the repository at this point in the history
Update installation.md
  • Loading branch information
baseplate-admin committed Dec 14, 2024
1 parent 366b2c8 commit ba445bd
Show file tree
Hide file tree
Showing 18 changed files with 58 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ This fork contains is a continuation of the work done by [`mariocesar`](https://
## Install


Please remember to uninstall `django-ltree` before installing `django-ltree-2`, since both uses `django_ltree` namespace.
Please remember to uninstall `django-ltree` before installing `django-ltree-2`, since both uses `django_ltree` namespace.


---
Expand Down
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Augmenting `django` orm with postgres `ltree <https://www.postgresql.org/docs/cu

installation
usage
indexes
manager

Indices and tables
Expand Down
25 changes: 25 additions & 0 deletions docs/indexes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Indexes

If you want to add index to your `TreeModel`, use [`GistIndex`](https://docs.djangoproject.com/en/5.1/ref/contrib/postgres/indexes/#gistindex) from [`postgres`](https://www.postgresql.org/docs/9.1/textsearch-indexes.html).

```{note}
Note: `GistIndex` was suggested based on [`@pauloxnet`](http://github.com/pauloxnet)'s code sample from this [microsoft citus con youtube video](https://www.youtube.com/watch?v=u8F7bTJVe_4&t=1051s)
```

To implement the index in your model:

```{code-block} python
:caption: models.py
from django.contrib.postgres import indexes as idx
from django_ltree import TreeModel
class CustomTree(TreeModel):
...
class Meta:
indexes = [
idx.GistIndex(fields=["path"]),
]
```
11 changes: 8 additions & 3 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,21 @@ Django 4.2 to 5.0 supported.

## Installation

```{attention}
Please remember to uninstall `django-ltree` before installing `django-ltree-2`, since both uses `django_ltree` namespace.
```

1. Install with **pip**:

```sh
```bash
python -m pip install django-ltree-2
```

2. Add django-ltree to your `INSTALLED_APPS`:

```python
# settings.py
```{code-block} python
:caption: settings.py
INSTALLED_APPS = [
...,
"django_ltree",
Expand Down
25 changes: 18 additions & 7 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

Lets assume that our model looks like this.

```python
# models.py
```{code-block} python
:caption: models.py
from django import models
from django_ltree import TreeModel
Expand All @@ -13,7 +14,9 @@ class CustomTree(TreeModel):

## Create a child without parent

```python
```{code-block} python
:caption: views.py
from .models import CustomTree
CustomTree.objects.create_child(text='Hello world')
Expand All @@ -26,7 +29,9 @@ tree)

Let's assume we want to add a child to the CustomTree object of `pk=1`

```python
```{code-block} python
:caption: views.py
from .models import CustomTree
# This must return a single object
Expand All @@ -38,7 +43,9 @@ CustomTree.objects.create_child(text='Hello world', parent=parent)

A root means the the object that childrens anchor to.

```python
```{code-block} python
:caption: views.py
from .models import CustomTree
roots: list[CustomTree] = CustomTree.objects.roots()
Expand All @@ -49,7 +56,9 @@ roots: list[CustomTree] = CustomTree.objects.roots()
To get the childrens of a object, we can first get the object then call
the QuerySet specific children function.

```python
```{code-block} python
:caption: views.py
from .models import CustomTree
instance = CustomTree.objects.get(pk=1)
Expand All @@ -65,7 +74,9 @@ the filter method.
Lets assume we want to get the childrens of `CustomTree`
object whose pk is 1.

```python
```{code-block} python
:caption: views.py
from .models import CustomTree
instance = CustomTree.objects.get(pk=1)
Expand Down
7 changes: 5 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ authors = [
"Mario César Señoranis Ayala <mariocesar@humanzilla.com>",
"Kimsia Sim",
]
maintainers = [
"baseplate-admin <61817579+baseplate-admin@users.noreply.github.com>",
]
license = "MIT"
readme = "README.md"
packages = [{include = "django_ltree"}]
classifiers = [
packages = [{ include = "django_ltree", from = "src" }]
classifiers = [
"Development Status :: 5 - Production/Stable",
"Framework :: Django",
"Framework :: Django :: 3.2",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit ba445bd

Please sign in to comment.