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-modelVerified import paths — ran on the pinned version, not inferred.
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.
Ensure your model's `Meta` class includes `ordering = ("order",)` (or your custom order field name) or directly inherits from `OrderedModel.Meta`.Review any code that modifies fields specified in `order_with_respect_to` to ensure the new auto-adjustment of ordering is desirable. Test thoroughly.
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.
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`.
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()})`).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')`).