Skip to content

[change] Standardize default ordering for timestamped models #727

Description

@nemesifier

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.

Metadata

Metadata

Assignees

Type

No type

Projects

Status
Backlog

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions