Skip to main content

Sort Order Field provides a Django model field for controlling sort order. The field includes an admin widget which makes it easy to arrange related models in an inline form.

At the moment, the admin widget assumes it is the only field which controls ordering for its model, and it has no awareness of the sort direction. This is less powerful than other sort field libraries, but its design may be useful for certain situations.

screencast showing sort buttons in action

Easy to use sort buttons.

screencast showing sort buttons in action

Accessible keyboard navigation and non-sequential sort indexes.

Installation

Add “sort_order_field” to your INSTALLED_APPS setting:

INSTALLED_APPS = [
    ...
    'sort_order_field',
]

Basic usage

Add a SortOrderField to one of your models:

from django.db import models
from sort_order_field import SortOrderField

class Poll(models.Model):
    question = models.CharField(max_length=100)

class PollOption(models.Model):
    class Meta:
        ordering = ('sort_order',)

    poll = models.ForeignKey('Poll', on_delete=models.CASCADE)
    sort_order = SortOrderField(_("Sort"))
    label = models.CharField(max_length=100)

Add the sortable model to an inline model admin for your parent model:

from django.contrib import admin
from . import models

class PollOptionInline(admin.TabularInline):
    model = models.PollOption
    fields = ('sort_order', 'label',)

@admin.register(models.Poll)
class PollAdmin(admin.ModelAdmin):
    fields = ('question',)
    inlines = (PollOptionInline,)

The sort order field will be rendered as a text field with JavaScript enhancements. When the user enters a new sort order value, the inline forms will be reorganized according to that value. The sort order fields will be bound by their initial values, which helps to avoid conflicts if the same objects appear in different inlines.

Release files for django-sort-order-field 1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-sort-order-field 1.2
File Size Uploaded
django-sort-order-field-1.2.tar.gz 6.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-sort-order-field 1.2
File Interpreter ABI Platform
django_sort_order_field-1.2-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 14.1 kB

Release files / django-sort-order-field-1.2.tar.gz

Download URL django-sort-order-field-1.2.tar.gz
Size 6.5 kB
Tags Source
SHA-256 checksum
How to use checksums
67f8556102b1e740e3712bb9bb0c6c3e63b90c85938a86272e1aaee606ae0650
BLAKE2b-256 checksum
How to use checksums
19711af3458400c270ac56fffdbf826c8bea74a56fe1bc3d0d1b5909148d333e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2

Release files / django_sort_order_field-1.2-py2.py3-none-any.whl

Download URL django_sort_order_field-1.2-py2.py3-none-any.whl
Size 7.6 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
6a68e3f28f50319430bbbb7dd3cb9b8b880b8b2b9f7f28a00e40f809ae3de014
BLAKE2b-256 checksum
How to use checksums
961fb0d19313ec6e588adc5c74f369da045cb9bf8f61176a72fdb1dd31b0ab65
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2

Release history Release notifications | RSS feed

This release

1.2 This release

2 release files

1.1

2 release files

1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page