Registry / web-framework / django-admin-sortable2

django-admin-sortable2

JSON →
library2.3.1pypypi✓ verified 25d ago

django-admin-sortable2 is a Django package that provides generic drag-and-drop ordering functionality for objects in the List, Stacked-Inline, and Tabular-Inline Views of the Django Admin interface. It enriches existing `ModelAdmin` and `InlineModelAdmin` classes with sortable behavior via mixins. The library is actively maintained, with frequent minor and patch releases to support newer Django and Python versions.

pip install django-admin-sortable2
INSTALL
IMPORT
SIG · DJANGO-ADMIN-SORTA
D
django-admin-sortable2
web-frameworkpythonv2.3.1
Install
3.5s avg
Import
Disk
66MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.3.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 66.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 3.5s · import 0.000s · 67MB
66MB installed
● package 66MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

SortableAdminMixin
from adminsortable2.admin import SortableAdminMixin
from adminsortable2.admin import SortableAdminMixin

This quickstart demonstrates how to make both a main ModelAdmin list view and its associated inline forms sortable. It requires adding `adminsortable2` to `INSTALLED_APPS`, defining a positive integer `order` field (with `default=0` and in `Meta.ordering`) in your models, and then applying `SortableAdminMixin` to your `ModelAdmin` and `SortableTabularInline` (or `SortableStackedInline`) to your inline admin classes. Remember to run `makemigrations` and `migrate` after defining your models.

import os # settings.py # INSTALLED_APPS = [ # ..., # 'adminsortable2', # 'your_app_name', # ] # your_app_name/models.py from django.db import models class Category(models.Model): name = models.CharField(max_length=100) order = models.PositiveIntegerField(default=0, blank=False, null=False, db_index=True) class Meta: ordering = ['order'] verbose_name_plural = 'Categories' def __str__(self): return self.name class Item(models.Model): category = models.ForeignKey(Category, on_delete=models.CASCADE) name = models.CharField(max_length=100) order = models.PositiveIntegerField(default=0, blank=False, null=False, db_index=True) class Meta: ordering = ['order'] def __str__(self): return self.name # your_app_name/admin.py from django.contrib import admin from adminsortable2.admin import SortableAdminMixin, SortableTabularInline from .models import Category, Item class ItemInline(SortableTabularInline): model = Item extra = 1 fields = ['name', 'order'] # 'order' can be omitted from 'fields' to be hidden @admin.register(Category) class CategoryAdmin(SortableAdminMixin, admin.ModelAdmin): list_display = ['name', 'order'] inlines = [ItemInline] # To run the example (after creating a Django project): # 1. Add 'adminsortable2' and 'your_app_name' to INSTALLED_APPS in settings.py. # 2. Run: python manage.py makemigrations your_app_name # 3. Run: python manage.py migrate # 4. Run: python manage.py createsuperuser # 5. Run: python manage.py runserver # 6. Access /admin/ and navigate to 'Categories' to test sorting.
Debug
Known issues
breakingVersion 2.0 introduced significant breaking changes, including replacing jQuery-UI with Sortable.js, removing extended Django admin templates, and dropping support for older Django (<=3.2) and Python (2.7, 3.4, 3.5) versions. Projects upgrading from 1.x must thoroughly review their code and update dependencies.
fix
Review the official documentation for migration guidelines when upgrading from 1.x. Ensure your Django version is 4.2 or higher, and Python is 3.9 or higher.
affects: < 2.0
gotchaThe model that you wish to make sortable must include a `PositiveIntegerField` for ordering (e.g., `order`) with `default=0`. This field must be the first element in the model's `Meta.ordering` tuple or list. For optimal performance, add `db_index=True`, and ensure it is not set to `editable=False`.
fix
Ensure your sortable model has `order = models.PositiveIntegerField(default=0, blank=False, null=False, db_index=True)` and `class Meta: ordering = ['order']`.
affects: All
gotchaWhen applying `django-admin-sortable2` to existing models, the `order` field for existing objects might be `0` or `null`, preventing proper sorting.
fix
After adding the order field, run the management command `./manage.py reorder <app_label.ModelName>` to automatically populate the `order` field for all existing instances.
affects: All
gotchaWhen reordering items within `StackedInline` or `TabularInline` views, the changes are not immediately saved to the database. The new order will only persist after the parent model's form is explicitly saved.
fix
Inform users that they must click the 'Save' button on the parent model's detail page after reordering inline items.
affects: All
gotchaIf you use a custom `formset` for your `SortableInlineAdminMixin` (e.g., `SortableTabularInline` or `SortableStackedInline`), that custom formset must inherit from `adminsortable2.admin.CustomInlineFormSet` in addition to `BaseInlineFormSet` to ensure sorting functionality works correctly.
fix
Update your custom inline formset class to inherit from `CustomInlineFormSet`, e.g., `class MyCustomFormSet(CustomInlineFormSet, BaseInlineFormSet): ...`
affects: All
Upgrade
Version history
2.3.1latest on PyPI · released Jan 22, 2026
Audit
Dependencies
DjangorequiredRequired for Django integration, minimum version 4.2.
Agent activity
7 hits · last 30 days
node
6
Resources
django-admin-sortable2 — pip install django-admin-sortable2 · libregistry