Skip to content

feat: Add system-wide custom bases settings for HistoricalRecords#1576

Open
rodrigobnogueira wants to merge 1 commit intodjango-commons:masterfrom
rodrigobnogueira:feature/system-wide-custom-bases
Open

feat: Add system-wide custom bases settings for HistoricalRecords#1576
rodrigobnogueira wants to merge 1 commit intodjango-commons:masterfrom
rodrigobnogueira:feature/system-wide-custom-bases

Conversation

@rodrigobnogueira
Copy link

@rodrigobnogueira rodrigobnogueira commented Dec 29, 2025

  • 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

Description

This PR implements system-wide settings for specifying custom HistoricalModel base classes. Users can now configure default base classes globally via Django settings instead of specifying the bases parameter for every HistoricalRecords instance.

New Settings:

  • SIMPLE_HISTORY_CUSTOM_BASES - Default base classes for regular historical models
  • SIMPLE_HISTORY_CUSTOM_M2M_BASES - Default base classes for M2M historical models

Before:

class Poll(models.Model):
    history = HistoricalRecords(bases=[IPAddressHistoricalModel])

class Article(models.Model):
    history = HistoricalRecords(bases=[IPAddressHistoricalModel])

After:

# settings.py
SIMPLE_HISTORY_CUSTOM_BASES = [IPAddressHistoricalModel]

# models.py
class Poll(models.Model):
    history = HistoricalRecords()  # Uses IPAddressHistoricalModel automatically

class Article(models.Model):
    history = HistoricalRecords()  # Uses IPAddressHistoricalModel automatically

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:

  • I have run the pre-commit run command to format and lint.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • I have added my name and/or github handle to AUTHORS.rst
  • I have added my change to CHANGES.rst
  • All new and existing tests passed.

- 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
@rodrigobnogueira rodrigobnogueira force-pushed the feature/system-wide-custom-bases branch from 71d71b4 to 9f17e23 Compare December 29, 2025 21:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Using custom HistoricalModel bases

1 participant