You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Normally m2m_changed signal is emitted with reverse = False where the forward relationship is updated. When the m2m changes are done on the reverse side of the relationship, the log entry changes aren't reported correctly, as in there's no way to logically follow the change.
E.g, say we have two classes
class Child(model.Model):
pass
class Parent(models.Model):
children = ManyToManyField(Child, related_name='parents')
then the log entry m2m change has a content_type of Parent, object_pk has the unique id of the parent that was changed, and changes has children changed in the "object"
Makes perfect sense. From this audit log, you can exactly work out what was changed. E.g.
parent = log_entry.content_type.model_class.get(object_pk=log_entry.object_pk)
field, field_value = next(iter(log_entry.changes))
children = getattr(parent, field).all()
# The children list will match that of the objects field in log_entry.changes
Normally m2m_changed signal is emitted with reverse = False where the forward relationship is updated. When the m2m changes are done on the reverse side of the relationship, the log entry changes aren't reported correctly, as in there's no way to logically follow the change.
E.g, say we have two classes
If the update is done forwards:
then the log entry m2m change has a content_type of Parent, object_pk has the unique id of the parent that was changed, and changes has children changed in the "object"
Makes perfect sense. From this audit log, you can exactly work out what was changed. E.g.
But if the update is done in a reverse manner
then the log_entry generated isn't correct, content_type has Child, object_pk has the unique id of the child and the changes are
Now if you try to do the same thing as above, you get an attribute error
The text was updated successfully, but these errors were encountered: