Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ Authors
- Nathan Villagaray-Carski (`ncvc <https://github.com/ncvc>`_)
- Nianpeng Li
- Nick Träger
- Noam Kushinsky (`noamkush <https://github.com/noamkush>`_)
- Noel James (`NoelJames <https://github.com/NoelJames>`_)
- Ofek Lev (`ofek <https://github.com/ofek>`_)
- Phillip Marshall
Expand Down
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Unreleased
- Added pagination to ``SimpleHistoryAdmin`` (gh-1277)
- Fixed issue with history button not working when viewing historical entries in the
admin (gh-527)
- Fixed history_change_reason_field being shared across inherited models (gh-1433)

3.7.0 (2024-05-29)
------------------
Expand Down
2 changes: 1 addition & 1 deletion simple_history/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ def copy_fields(self, model):
def _get_history_change_reason_field(self):
if self.history_change_reason_field:
# User specific field from init
history_change_reason_field = self.history_change_reason_field
history_change_reason_field = self.history_change_reason_field.clone()
elif getattr(
settings, "SIMPLE_HISTORY_HISTORY_CHANGE_REASON_USE_TEXT_FIELD", False
):
Expand Down
14 changes: 14 additions & 0 deletions simple_history/tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,12 @@ class Meta:
abstract = True


class TrackedAbstractBaseWithReasonField(models.Model):
history = HistoricalRecords(
inherit=True, history_change_reason_field=models.TextField()
)


class UntrackedAbstractBase(models.Model):
class Meta:
abstract = True
Expand Down Expand Up @@ -709,6 +715,14 @@ class InheritTracking4(TrackedAbstractBaseA):
pass


class InheritReasonField1(TrackedAbstractBaseWithReasonField):
pass


class InheritReasonField2(TrackedAbstractBaseWithReasonField):
pass


class BasePlace(models.Model):
name = models.CharField(max_length=50)
history = HistoricalRecords(inherit=True, table_name="base_places_history")
Expand Down
25 changes: 25 additions & 0 deletions simple_history/tests/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@
HistoricalPollWithManyToMany_places,
HistoricalState,
InheritedRestaurant,
InheritReasonField1,
InheritReasonField2,
Library,
ManyToManyModelOther,
ModelWithCustomAttrOneToOneField,
Expand Down Expand Up @@ -686,6 +688,29 @@ def test_user_textfield_history_change_reason(self):
self.assertTrue(isinstance(field, models.TextField))
self.assertEqual(history.history_change_reason, reason)

def test_inherited_history_change_reason_update(self):
inherited1 = InheritReasonField1.history.create(
history_change_reason="reason1", id=1, history_date=datetime.now()
)
inherited2 = InheritReasonField2.history.create(
history_change_reason="reason2", id=1, history_date=datetime.now()
)

InheritReasonField1.history.update(history_change_reason="new_reason1")
InheritReasonField2.history.update(history_change_reason="new_reason2")

inherited1.refresh_from_db()
inherited2.refresh_from_db()

self.assertEqual(inherited1.history_change_reason, "new_reason1")
self.assertEqual(inherited2.history_change_reason, "new_reason2")

def test_history_change_reason_field_not_shared(self):
self.assertIsNot(
InheritReasonField1.history.model._meta.get_field("history_change_reason"),
InheritReasonField2.history.model._meta.get_field("history_change_reason"),
)

def test_history_diff_includes_changed_fields(self):
p = Poll.objects.create(question="what's up?", pub_date=today)
p.question = "what's up, man?"
Expand Down