Skip to content

Commit 869ae77

Browse files
committed
Added default prefix field to HistoricalRecords
1 parent eff5796 commit 869ae77

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

simple_history/models.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ def _history_user_setter(historical_instance, user):
7171

7272

7373
class HistoricalRecords:
74+
DEFAULT_MODEL_NAME_PREFIX = "Historical"
75+
7476
thread = context = LocalContext() # retain thread for backwards compatibility
7577
m2m_models = {}
7678

@@ -230,7 +232,7 @@ def finalize(self, sender, **kwargs):
230232

231233
def get_history_model_name(self, model):
232234
if not self.custom_model_name:
233-
return f"Historical{model._meta.object_name}"
235+
return f"{self.DEFAULT_MODEL_NAME_PREFIX}{model._meta.object_name}"
234236
# Must be trying to use a custom history model name
235237
if callable(self.custom_model_name):
236238
name = self.custom_model_name(model._meta.object_name)

simple_history/tests/tests/test_models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,7 @@ def test_get_next_record_with_excluded_field(self):
898898
class CreateHistoryModelTests(unittest.TestCase):
899899
@staticmethod
900900
def create_history_model(model, inherited):
901-
custom_model_name_prefix = "MockHistorical"
901+
custom_model_name_prefix = f"Mock{HistoricalRecords.DEFAULT_MODEL_NAME_PREFIX}"
902902
records = HistoricalRecords(
903903
# Provide a custom history model name, to prevent name collisions
904904
# with existing historical models
@@ -912,7 +912,7 @@ def assert_tracked_fields_equal(model, expected_field_names):
912912
from .. import models
913913

914914
history_model = getattr(
915-
models, f"Historical{model.__name__}"
915+
models, f"{HistoricalRecords.DEFAULT_MODEL_NAME_PREFIX}{model.__name__}"
916916
)
917917
self.assertListEqual(
918918
[field.name for field in history_model.tracked_fields],

0 commit comments

Comments
 (0)