Registry / database / django-ordered-model

django-ordered-model

JSON →
library3.7.4pypypiunverified

django-ordered-model is a Django library that enables models to be ordered, providing a simple admin interface for reordering them. It is actively maintained, with frequent updates, including a recent alpha release for version 3.8.0. The current stable version is 3.7.4.

pip install django-ordered-model
INSTALL
IMPORT
SIG · DJANGO-ORDERED-MOD
D
django-ordered-model
databasepythonv3.7.4
Install
1.5s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v3.7.4 · 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.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 18MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.5s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

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

OrderedModel
from ordered_model.models import OrderedModel
from ordered_model import OrderedModel

Define a model inheriting from `OrderedModel` and register it with `OrderedModelAdmin` in the Django admin to enable reordering functionality. Ensure 'ordered_model' is in `INSTALLED_APPS` and run migrations.

from django.db import models from django.contrib import admin from ordered_model.models import OrderedModel from ordered_model.admin import OrderedModelAdmin # models.py class Item(OrderedModel): name = models.CharField(max_length=100) class Meta(OrderedModel.Meta): verbose_name = "Item" verbose_name_plural = "Items" # admin.py class ItemAdmin(OrderedModelAdmin): list_display = ('name', 'move_up_down_links') admin.site.register(Item, ItemAdmin)
Debug
Known issues
breakingSubclasses of `OrderedModelBase` (including `OrderedModel`) must explicitly specify `Meta.ordering`. Failing to do so will emit a system `Check` failure since version 3.7.
fix
Ensure your model's `Meta` class includes `ordering = ("order",)` (or your custom order field name) or directly inherits from `OrderedModel.Meta`.
affects: >=3.7
breakingSince version 3.7, updating fields that are part of `order_with_respect_to` now correctly adjusts the ordering. This is a behavioral change that might impact existing logic if it relied on the previous, potentially incorrect, behavior.
fix
Review any code that modifies fields specified in `order_with_respect_to` to ensure the new auto-adjustment of ordering is desirable. Test thoroughly.
affects: >=3.7
gotchaIf you use a custom `ModelManager` or `QuerySet` with an `OrderedModel`, they must inherit from `OrderedModelManager` or `OrderedModelQuerySet` respectively. Failing to do so will raise Django `Check` errors (E003/E004). As of 3.7.4, this is relaxed to a warning if the manager returns the correct queryset.
fix
Ensure your custom manager inherits from `OrderedModelManager` and your custom queryset from `OrderedModelQuerySet`. See the `django-ordered-model` README for examples of intermediate classes with multiple inheritance if needed.
affects: >=3.7.2 (strict check), >=3.7.4 (relaxed to warning)
gotchaWhen using `order_with_respect_to`, the library implicitly sets an internal `_order` field for ordering. Therefore, `order_with_respect_to` and `Meta.ordering` cannot be used simultaneously in the same model's `Meta` class and will raise a Django error.
fix
Do not specify `Meta.ordering` when `order_with_respect_to` is already defined, as the ordering is implicitly handled by the `_order` field created by `order_with_respect_to`.
affects: All versions
gotchaMethods like `to()`, `up()`, `down()`, `top()`, `bottom()`, and `delete()` use Django's `update()` method for performance when shifting other objects. This means custom `save()` logic or `DateTimeField(auto_now=True)` on *other shifted objects* will not be called. For the target object itself, `save()` is called if not directly manipulating `order` field.
fix
If you need `save()` logic or `auto_now` fields to update on *shifted objects*, use the `extra_update` parameter on ordering methods (e.g., `item.to(new_pos, extra_update={'modified': timezone.now()})`).
affects: All versions
gotchaDjango's `ManyToManyField` does not inherently respect `Meta.ordering` on intermediate (through) models when querying the 'members' queryset (e.g., `pizza.toppings.all()`).
fix
Use `ordered_model.fields.OrderedManyToManyField` or explicitly add an `order_by()` clause to your ManyToMany queryset (e.g., `pizza.toppings.all().order_by('pizzatoppingsthroughmodel__order')`).
affects: All versions
Upgrade
Version history
3.7.4latest on PyPI · released Mar 17, 2023
Audit
Dependencies
DjangorequiredCore framework for the library.
djangorestframeworkoptionalRequired for `OrderedModelSerializer` to handle DRF API ordering.
Agent activity
7 hits · last 30 days
node
6
Resources
django-ordered-model — pip install django-ordered-model · libregistry