django-easy-audit icon indicating copy to clipboard operation
django-easy-audit copied to clipboard

Fix to handle proxy model and multiple M2M situations

Open rgegriff opened this issue 1 year ago • 1 comments

I ran into some issues dealing with M2M relationships resulting in "null" being recorded as the fieldname for adds/removes on changes to proxy models which led me to #207

This PR re-writes get_m2m_field_name to use the sender that gets passed to the signal handler, which happens to be the through model.

Given the through model, the changed instance, and the added model; we can uniquely determine which field on the instance model was changed, even if the originating model has multiple M2M relationships with the remote model (since each will use a different intermediate model).

There was also an issue that I didn't see in the issue tracker that came up for me; if the changed instance was a proxy model then get_m2m_field_name would return None . This also resolves that issue since we are searching for the field directly

rgegriff avatar Jan 27 '24 18:01 rgegriff

Added some tests

rgegriff avatar Jan 29 '24 18:01 rgegriff