diff --git a/simple_history/tests/admin.py b/simple_history/tests/admin.py index 24cf5f7a..a625edcd 100644 --- a/simple_history/tests/admin.py +++ b/simple_history/tests/admin.py @@ -10,6 +10,7 @@ Document, Employee, FileModel, + Group, Paper, Person, Planet, @@ -43,6 +44,7 @@ def test_method(self, obj): history_list_display = ["title", "test_method"] +admin.site.register(Group, SimpleHistoryAdmin) admin.site.register(Poll, SimpleHistoryAdmin) admin.site.register(Choice, ChoiceAdmin) admin.site.register(Person, PersonAdmin) diff --git a/simple_history/tests/models.py b/simple_history/tests/models.py index 99c6a2f8..6f1375e1 100644 --- a/simple_history/tests/models.py +++ b/simple_history/tests/models.py @@ -145,6 +145,28 @@ class PollWithManyToMany(models.Model): history = HistoricalRecords(m2m_fields=[places]) +class Membership(models.Model): + group = models.ForeignKey("Group", on_delete=models.CASCADE) + person = models.ForeignKey("Person", on_delete=models.CASCADE) + inviter = models.ForeignKey( + "Person", + on_delete=models.CASCADE, + related_name="membership_invites", + ) + invite_reason = models.CharField(max_length=64) + + +class Group(models.Model): + name = models.CharField(max_length=128) + members = models.ManyToManyField( + "Person", + through="tests.Membership", + through_fields=("group", "person"), + ) + + history = HistoricalRecords(m2m_fields=[members]) + + class PollWithManyToManyCustomHistoryID(models.Model): question = models.CharField(max_length=200) pub_date = models.DateTimeField("date published") diff --git a/simple_history/tests/tests/test_models.py b/simple_history/tests/tests/test_models.py index 484df73f..d5228100 100644 --- a/simple_history/tests/tests/test_models.py +++ b/simple_history/tests/tests/test_models.py @@ -101,6 +101,7 @@ PollWithHistoricalIPAddress, PollWithManyToMany, PollWithManyToManyCustomHistoryID, + Group, PollWithManyToManyWithIPAddress, PollWithNonEditableField, PollWithSelfManyToMany, @@ -1939,6 +1940,12 @@ def setUp(self): self.poll = self.model.objects.create(question="what's up?", pub_date=today) +class GroupWithManyToManyThroughFieldsTest(TestCase): + def setUp(self): + self.model = Group + self.history_model = self.model.history.model + + class ManyToManyTest(TestCase): def setUp(self): self.model = PollWithManyToMany