Allows items of a collection to be manually sorted(such as for use with drag-and-drop).
Project description
Django Subjective Sort
Installation
$ pip install django-subjective-sort
Usage
- Extend the
Sortable
class to add custom sorting logic to any Django model.
# 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'])
- Apply migrations.
$ python manage.py makemigrations
$ python manage.py migrate
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for django-subjective-sort-0.2.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | b48444feed2255fc26264ffdfa5248553c0533dfa2be4d3b804192d506e25011 |
|
MD5 | f00fb0a93d47ac07156c73450499beec |
|
BLAKE2b-256 | 0a7abdac8757637535dbbf3f81a6e4527cae63486b12351a77c9dff4844be3aa |
Close
Hashes for django_subjective_sort-0.2.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2f957ab729175d6c63d1b331795298b58f081fb2af72e775d74da16fd5d69544 |
|
MD5 | f9f5cead841e8570bc7f80e57627fdd5 |
|
BLAKE2b-256 | 8489e740e046d2cdc3e61d95bf5deb32e6d6479e3cbd6c5eda4d6a8254211241 |