Implement django-natural-keys
as base for BaseModel
#2900
Labels
impact: breaking change
This change or feature will remove or replace existing functionality; needs to be an X.0.0 release
type: housekeeping
Changes to the application which do not directly impact the end user
Milestone
Proposed Changes
Base models should inherit from
django-natural-keys
baseNaturalKeyModel
and useNaturalKeyModelManager
so that…natural_key()
is automatically provided using the uniqueness constraintsnatural_key()
methodFoo.objects.get_by_natural_key()
is also automatically provided, reducing boilerplateRestrictedQuerySet
in order to publish aget_by_natural_key()
methodobjects = FooRestrictedQuerySet.as_manager()
on the modelnatural_key_slug
that is immutable derived from the natural key fields for that object. This can be used in URL fragments in the "natural key or PK" pattern we have begun to adopt for filters.Justification
We have decided to align around natural keys. We need less boilerplate, not more. In the common case, this should work automatically and result in objects having deterministic uniqueness/natural key constraints with minimal effort. For the uncommon/edge case, we will need to adapt and revise the pattern.
The text was updated successfully, but these errors were encountered: