From a85df3071c2634e46ccb8bc6d7420f25779b3ce0 Mon Sep 17 00:00:00 2001 From: Marti Markov Date: Sun, 12 Jan 2025 11:24:38 +0000 Subject: [PATCH] Use tuple for m2m_models --- AUTHORS.rst | 1 + simple_history/models.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/AUTHORS.rst b/AUTHORS.rst index 16602a25..e6ed1d17 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -97,6 +97,7 @@ Authors - Marcelo Canina (`marcanuy `_) - Marco Sirabella - Mark Davidoff +- Marti Markov (`martimarkov `_) - Martin Bachwerk - Marty Alchin - Matheus Cansian (`mscansian `_) diff --git a/simple_history/models.py b/simple_history/models.py index b007efbf..3b10b4b1 100644 --- a/simple_history/models.py +++ b/simple_history/models.py @@ -245,7 +245,7 @@ def finalize(self, sender, **kwargs): m2m_model = self.create_history_m2m_model( history_model, field.remote_field.through ) - self.m2m_models[field] = m2m_model + self.m2m_models[(sender._meta.object_name, field)] = m2m_model setattr(module, m2m_model.__name__, m2m_model) @@ -706,7 +706,7 @@ def m2m_changed(self, instance, action, attr, pk_set, reverse, **_): def create_historical_record_m2ms(self, history_instance, instance): for field in history_instance._history_m2m_fields: - m2m_history_model = self.m2m_models[field] + m2m_history_model = self.m2m_models[(instance._meta.object_name, field)] original_instance = history_instance.instance through_model = getattr(original_instance, field.name).through through_model_field_names = [f.name for f in through_model._meta.fields]