django-sortedm2m
Drop-in replacement for Django's many to many field with sorted relations.
Decision gist · record as of 2026-08-14
Yes. This is a well-maintained, production-stable package with no known vulnerabilities, low install friction, and a permissive license. It solves a real Django limitation (unordered many-to-many relations) with a straightforward drop-in replacement. Use it whenever you need to preserve relation order in a Django model.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Requires Django 4.2, 5.0, or 5.1; add 'sortedm2m' to INSTALLED_APPS to use the admin widget and its CSS/JS assets.
- Low friction installation with no runtime dependencies.
- Actively maintained with recent releases supporting Django 5.1 and Python 3.7–3.12; repository shows steady activity and 525 stars.
License · maintenance · safety
BSD (permissive) — BSD license is permissive; you can use, modify, and distribute this package with minimal restrictions, provided you include the license notice.
last release 2024-08-11 (733 days) · last repo commit 2026-08-10 · 525 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 389,270 downloads/mo, #7,032 on PyPI
Alternatives
Verify before relying
pip install django-sortedm2m
from sortedm2m.fields import SortedManyToManyField
from django.db import models
class Gallery(models.Model):
photos = SortedManyToManyField('Photo')
gallery = Gallery.objects.create(name='My Gallery')
for photo in Photo.objects.order_by('name'):
gallery.photos.add(photo) # order is preserved- Whether the package supports Django versions earlier than 4.2 (version 4.0.0 dropped support for outdated versions, but exact cutoff is unclear).
- Performance characteristics when managing large numbers of related objects or complex sort operations.
What it is and what it does
django-sortedm2m is a Django field that works exactly like the built-in ManyToManyField but remembers the order in which you add related objects. Instead of getting relations back in an arbitrary order, you get them in the order you added them, with the sort position stored in the database. This is useful for galleries, playlists, or any scenario where the sequence of related items matters.
The package provides a SortedManyToManyField class you drop into your models in place of ManyToManyField, and an optional admin widget that lets you reorder relations by dragging and dropping. It handles database migrations automatically and supports Django 4.2 through 5.1 on Python 3.7–3.12. There are no runtime dependencies beyond Django itself.
Use it for
- Gallery or portfolio models where photos must appear in a specific sequence chosen by the user.
- Playlist or media collection models where track or item order is part of the data model.
- Admin interfaces where users need to reorder many-to-many relationships via drag-and-drop.
- Legacy database integration where you need to rename the sort field to match existing schema.
- Custom through models where you want to add a __str__ method to improve admin display of relationships.
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes.
This is a well-maintained, production-stable package with no known vulnerabilities, low install friction, and a permissive license. It solves a real Django limitation (unordered many-to-many relations) with a straightforward drop-in replacement. Use it whenever you need to preserve relation order in a Django model.
Install
django-sortedm2m on PyPI
Before you install
Low friction installation with no runtime dependencies. Actively maintained with recent releases supporting Django 5.1 and Python 3.7–3.12; repository shows steady activity and 525 stars.
Requires Django 4.2, 5.0, or 5.1; add 'sortedm2m' to INSTALLED_APPS to use the admin widget and its CSS/JS assets.
License in practice
BSD license is permissive; you can use, modify, and distribute this package with minimal restrictions, provided you include the license notice.
Quickstart
pip install django-sortedm2m
from sortedm2m.fields import SortedManyToManyField
from django.db import models
class Gallery(models.Model):
photos = SortedManyToManyField('Photo')
gallery = Gallery.objects.create(name='My Gallery')
for photo in Photo.objects.order_by('name'):
gallery.photos.add(photo) # order is preserved
Verify before relying
- Whether the package supports Django versions earlier than 4.2 (version 4.0.0 dropped support for outdated versions, but exact cutoff is unclear).
- Performance characteristics when managing large numbers of related objects or complex sort operations.
Package facts
| License | BSD permissive |
| Python support | Not specified |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | None |
| Maintenance | Actively maintained 733 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 389,270 / month, #7,032 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | Development Status :: 5 - Production/StableEnvironment :: Web EnvironmentFramework :: DjangoFramework :: Django :: 4.2Framework :: Django :: 5.0Framework :: Django :: 5.1Intended Audience :: DevelopersLicense :: OSI Approved :: BSD LicenseNatural Language :: EnglishOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9 |
Evidence: django_sortedm2m-4.0.0-py2.py3-none-any.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “django ordered many to many”
- django-sortedm2mProvides a drop-in replacement for Django's ManyToManyField that…
- django-admin-list-filter-dropdownRenders Django admin list filters as dropdown menus instead of long…
- django-admin-inline-paginator-plusAdds pagination to Django admin inline forms, allowing you to display…
Give your agent the search over MCP, or paste the wish link into any chat.
More Dynamic Content packages
MarkupSafe provides a text object that escapes special characters so untrusted strings can be safely embedded in HTML and XML without injection attacks.
Jinja2 is a templating engine that renders dynamic content by combining templates with Python-like syntax and data, supporting template inheritance, macros, autoescaping, and sandboxed execution.
Soupsieve is a CSS selector library designed to work with Beautiful Soup 4 to select, match, and filter HTML and XML elements using modern CSS selectors from CSS level 1 through CSS level 4 specifications.
Install it if you use Beautiful Soup for HTML or XML parsing and want modern CSS selector support.
Werkzeug is a WSGI utility library providing request/response objects, URL routing, an interactive debugger, HTTP utilities, and a development server for building web applications.
Flask is a lightweight WSGI web application framework for building web applications in Python, from simple single-page sites to complex multi-route applications.
Mako compiles Python-embedded templates into Python modules for fast rendering, supporting layout inheritance, custom functions, and direct Python expressions within template syntax.
See also django-ajax-selects · django-more-admin-filters · django-taggit · django-reverse-admin · django-admin-sortable2 · django-ordered-model · django-recurrence · django-modelcluster · dj-inmemorystorage · django-safedelete