openwisp / openwisp/openwisp-utils
[change] Standardize default ordering for timestamped models
@nemesifier is already working on this.
Since Aug 3, 2026.
- Dominant language
- Python
- Stars
- 93
- Forks
- 104
- Avg merge
- 14h 10m
- Merged PRs (30d)
- 22
Description
Is this change related to a problem? Please describe.
Models inheriting TimeStampedEditableModel provide created and modified timestamps but have no default ordering. Paginating an unordered queryset emits Django's UnorderedObjectListWarning and makes page membership non-deterministic.
A default ordering belongs in the shared timestamped model so that direct descendants have a deterministic newest-first queryset without every project repeating the same declaration.
Describe the change you'd like
Add ordering = ("-created",) to TimeStampedEditableModel.Meta.
Update local concrete test models that define their own Meta class to inherit TimeStampedEditableModel.Meta, so they preserve the shared ordering.
Add metadata-only AlterModelOptions migrations for metric_collection.Consent and the test-project Shelf and Book models.
Add regression tests that assert effective ordering for direct and Meta-overriding descendants. Update the autocomplete test to choose the expected shelf by label rather than relying on an unordered result position.
Describe alternatives you've considered
Add explicit ordering independently to every admin and REST view. This duplicates policy and leaves non-view querysets unordered.
Add ordering only to application models. This does not establish a reusable default for future direct descendants.
Additional context
A subclass that declares its own Meta must inherit TimeStampedEditableModel.Meta to preserve the shared ordering. Explicit Meta.ordering and QuerySet.order_by() continue to override the default.
This changes query semantics but not database schema. Django records model options in migration state, so the affected local models require metadata-only migrations. Consumers should audit .first(), .last(), distinct(), reverse relation managers, and paginated default querysets before adopting the new default.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.