Skip to main content

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

  1. 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'])
  1. Apply migrations.
    $ python manage.py makemigrations
    $ python manage.py migrate

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-subjective-sort-0.2.1.tar.gz (3.1 kB view hashes)

Uploaded Source

Built Distribution

django_subjective_sort-0.2.1-py3-none-any.whl (3.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page