feat: Add system-wide custom bases settings for HistoricalRecords#1576
Open
rodrigobnogueira wants to merge 1 commit intodjango-commons:masterfrom
Open
feat: Add system-wide custom bases settings for HistoricalRecords#1576rodrigobnogueira wants to merge 1 commit intodjango-commons:masterfrom
rodrigobnogueira wants to merge 1 commit intodjango-commons:masterfrom
Conversation
- Add SIMPLE_HISTORY_CUSTOM_BASES setting for default historical model bases - Add SIMPLE_HISTORY_CUSTOM_M2M_BASES setting for M2M historical model bases - Explicit bases/m2m_bases parameters override settings (backward compatible) - Add comprehensive documentation with examples - Add test models and test cases for both settings - All 342 tests passing Fixes django-commons#1574
71d71b4 to
9f17e23
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR implements system-wide settings for specifying custom
HistoricalModelbase classes. Users can now configure default base classes globally via Django settings instead of specifying thebasesparameter for everyHistoricalRecordsinstance.New Settings:
SIMPLE_HISTORY_CUSTOM_BASES- Default base classes for regular historical modelsSIMPLE_HISTORY_CUSTOM_M2M_BASES- Default base classes for M2M historical modelsBefore:
After:
Related Issue
Fixes #1574
Motivation and Context
Users who want to add custom fields or methods to all their historical models (e.g., tracking IP addresses or session information) currently need to specify the same bases parameter repeatedly for every
HistoricalRecords()instance. This leads to code duplication and makes it harder to maintain consistency across the codebase.This change allows users to configure custom bases once in their Django settings, eliminating the need for repetitive code while still allowing per-model overrides when needed.
How Has This Been Tested?
Test Environment:
Python 3.14
Django 6.0
All 342 existing tests + 4 new tests
Types of changes
New feature (non-breaking change which adds functionality)
Checklist:
pre-commit runcommand to format and lint.AUTHORS.rstCHANGES.rst