Metadata-Version: 2.1
Name: django-subjective-sort
Version: 0.2.1
Summary: Allows items of a collection to be manually sorted(such as for use with drag-and-drop).
Home-page: https://github.com/builtbykrit/django-subjective-sort
Author: Michael Prather
Author-email: michael@krit.com
Project-URL: Bug Tracker, https://github.com/builtbykrit/django-subjective-sort/issues
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Framework :: Django :: 4.1
Requires-Python: >=3.6
Description-Content-Type: text/markdown
License-File: LICENSE

# Django Subjective Sort

## Installation

```shell
    $ pip install django-subjective-sort
```

## Usage

1. Extend the `Sortable` class to add custom sorting logic to any Django model.

```python
# food/models.py
from typing import List

from django.db import models

from src.django_subjective_sort.models import Sortable


class Food(Sortable):
    name = models.CharField(max_length=255)

    # Extend the `Sortable` class to save sorting order.
    # This allows flexibility to save other changes simultaneously.
    def reposition(self,
                   peers: List['Food'],
                   position: int = None) -> List['Food']:
        sortables_affected = super().reposition(peers, position) + [self]
        # Save the changes
        return Food.objects.bulk_update(sortables_affected, ['position'])
```

2. Apply migrations.

```shell
    $ python manage.py makemigrations
    $ python manage.py migrate
```
