django-lexorank
This package implements an algorithm similar to JIRA's lexorank, but without using buckets for rebalancing that can be used with Django projects.
Installation
pip install django-lexorank
Configuration
Add django_lexorank to your INSTALLED_APPS setting:
INSTALLED_APPS = [
...
"django_lexorank",
]
Usage
Defining models
To add ranking to your model, you need to inherit it from RankedModel.
There are 2 ways of using RankedModel:
Globally
This way, all the objects will be ranked together in the global scope.
Example:
from django_lexorank.models import RankedModel
from django.db import models
class Board(RankedModel):
name = models.CharField(max_length=255)
Per group
This way, instances of the model will be ranked separately per group.
To do that, you have to set a name of the foreign key to the group
to the order_with_respect_to parameter of the model.
Example:
from django_lexorank.models import RankedModel
from django.db import models
class Task(RankedModel):
name = models.CharField(max_length=255)
board = models.ForeignKey("Board", on_delete=models.CASCADE, related_name="tasks")
order_with_respect_to = "board"
Field parameters
By default, new instances of the model will be ranked at the top of the list.
Rank field may accept boolean parameter insert_to_bottom to override this behaviour.
Example:
from django_lexorank.models import RankedModel
from django_lexorank.fields import RankField
from django.db import models
class User(RankedModel):
name = models.CharField(max_length=255)
rank = RankField(insert_to_bottom=True)
Manager methods
There are 3 ways to insert models using manager methods:
model.objects.create(**kwargs) - will use the default behaviour specified on RankField definition.
model.objects.add_to_bottom(**kwargs) - will insert the model at the bottom of the list.
model.objects.add_to_top(**kwargs) - will insert the model at the top of the list.
Instance methods
obj.place_after(after_obj) - places model instance after provided instance.
If rank length exceeds the limit after the move, rebalancing will be scheduled.
obj.place_before(before_obj) - places model instance before provided instance.
If rank length exceeds the limit after the move, rebalancing will be scheduled.
obj.place_on_top() - moves model instance to the bottom of the list.
If rank length exceeds the limit after the move, rebalancing will be scheduled.
obj.place_on_bottom() - moves model instance to the bottom of the list.
If rank length exceeds the limit after the move, rebalancing will be scheduled.
obj.get_previous_object() - return previous object in the list
obj.get_next_object() - return next object in the list
obj.get_previous_object_rank() - return previous object rank in the list
obj.get_next_object_rank() - return next object rank in the list
obj.schedule_rebalancing() - schedule rebalancing for the whole list or a group if order_with_respect_to is set
obj.rebalance() - rebalance the whole list or a group if order_with_respect_to is set
obj.rebalancing_required() - returns True if rebalancing is required for the whole list,
or for a group if order_with_respect_to is set
obj.rebalancing_scheduled() - returns True if rebalancing is scheduled for the whole list,
or for a group if order_with_respect_to is set
Model methods
model.get_first_object() - return first object in the list
model.get_last_object() - return last object in the list
model.get_first_object_rank() - return first object rank in the list
model.get_last_object_rank() - return last object rank in the list
Rebalancing Schedule
Each time, a rank length exceeds the limit, rebalancing is scheduled for the whole list or a group,
according to the value of order_with_respect_to parameter.
SheduledRebalancing model can be used to create a task for rebalancing ranks.
Metadata
Release files for django-lexorank 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| django_lexorank-0.1.4.tar.gz | 8.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_lexorank-0.1.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 20.0 kB
Release files / django_lexorank-0.1.4.tar.gz
| Download URL | django_lexorank-0.1.4.tar.gz |
|---|---|
| Size | 8.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
02080fec49a1aaad4aa70bfb3b5fa376737aa23af0447fae2a919bcbaf728203
|
|
BLAKE2b-256 checksum How to use checksums |
447cb674c916e68c190545eaf797bcb4660717c464f5e70d5a69ee990106f01a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.4 CPython/3.11.0 Linux/6.11.0-1018-azure
|
Release files / django_lexorank-0.1.4-py3-none-any.whl
| Download URL | django_lexorank-0.1.4-py3-none-any.whl |
|---|---|
| Size | 11.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1445940c49bb6d63ec7bff09a772426aca54c17166e9ce1afe97fc7cd0108948
|
|
BLAKE2b-256 checksum How to use checksums |
1ff69d568c9fa0cd539dce49f99e6a951009ca3b8350f5b4cb69f3d49f13fd21
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.4 CPython/3.11.0 Linux/6.11.0-1018-azure
|
Security for django-lexorank 0.1.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.