{"id":6595,"library":"django-ordered-model","title":"django-ordered-model","description":"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.","status":"active","version":"3.7.4","language":"en","source_language":"en","source_url":"https://github.com/django-ordered-model/django-ordered-model","tags":["django","model","ordering","admin","orm"],"install":[{"cmd":"pip install django-ordered-model","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core framework for the library.","package":"Django","optional":false},{"reason":"Required for `OrderedModelSerializer` to handle DRF API ordering.","package":"djangorestframework","optional":true}],"imports":[{"symbol":"OrderedModel","correct":"from ordered_model.models import OrderedModel"},{"note":"Use this base class if you want to use an existing field for ordering or customize the order field name.","symbol":"OrderedModelBase","correct":"from ordered_model.models import OrderedModelBase"},{"note":"Required if you use a custom ModelManager; it must inherit from this class.","symbol":"OrderedModelManager","correct":"from ordered_model.models import OrderedModelManager"},{"note":"Required if your custom ModelManager returns a custom QuerySet; it must inherit from this class.","symbol":"OrderedModelQuerySet","correct":"from ordered_model.models import OrderedModelQuerySet"},{"note":"For integrating ordering controls into the Django admin.","symbol":"OrderedModelAdmin","correct":"from ordered_model.admin import OrderedModelAdmin"},{"note":"For integrating ordering into Django REST Framework serializers.","symbol":"OrderedModelSerializer","correct":"from ordered_model.serializers import OrderedModelSerializer"},{"note":"Use this field for ManyToMany relationships to ensure correct ordering on the 'members' queryset.","symbol":"OrderedManyToManyField","correct":"from ordered_model.fields import OrderedManyToManyField"},{"note":"For reordering ManyToMany relationships in the admin via a tabular inline.","symbol":"OrderedTabularInline","correct":"from ordered_model.admin import OrderedTabularInline"}],"quickstart":{"code":"from django.db import models\nfrom django.contrib import admin\nfrom ordered_model.models import OrderedModel\nfrom ordered_model.admin import OrderedModelAdmin\n\n# models.py\nclass Item(OrderedModel):\n    name = models.CharField(max_length=100)\n\n    class Meta(OrderedModel.Meta):\n        verbose_name = \"Item\"\n        verbose_name_plural = \"Items\"\n\n# admin.py\nclass ItemAdmin(OrderedModelAdmin):\n    list_display = ('name', 'move_up_down_links')\n\nadmin.site.register(Item, ItemAdmin)","lang":"python","description":"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."},"warnings":[{"fix":"Ensure your model's `Meta` class includes `ordering = (\"order\",)` (or your custom order field name) or directly inherits from `OrderedModel.Meta`.","message":"Subclasses of `OrderedModelBase` (including `OrderedModel`) must explicitly specify `Meta.ordering`. Failing to do so will emit a system `Check` failure since version 3.7.","severity":"breaking","affected_versions":">=3.7"},{"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.","message":"Since 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.","severity":"breaking","affected_versions":">=3.7"},{"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.","message":"If 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.","severity":"gotcha","affected_versions":">=3.7.2 (strict check), >=3.7.4 (relaxed to warning)"},{"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`.","wrong":"class Meta:\n    ordering = ('order',)\n    order_with_respect_to = 'parent'","message":"When 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.","severity":"gotcha","affected_versions":"All versions"},{"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()})`).","message":"Methods 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.","severity":"gotcha","affected_versions":"All versions"},{"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')`).","message":"Django's `ManyToManyField` does not inherently respect `Meta.ordering` on intermediate (through) models when querying the 'members' queryset (e.g., `pizza.toppings.all()`).","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[]}