Closes #21303: Cache serialized post-change data on object

This commit is contained in:
Jeremy Stretch
2026-01-29 16:38:23 -05:00
parent c44e8606f7
commit d9b8caef5f
2 changed files with 4 additions and 3 deletions
+2 -2
View File
@@ -53,9 +53,9 @@ def serialize_for_event(instance):
def get_snapshots(instance, event_type):
snapshots = {
'prechange': getattr(instance, '_prechange_snapshot', None),
'postchange': None,
'postchange': getattr(instance, '_postchange_snapshot', None),
}
if event_type != OBJECT_DELETED:
if snapshots['postchange'] is None and event_type != OBJECT_DELETED:
# Use model's serialize_object() method if defined; fall back to serialize_object() utility function
if hasattr(instance, 'serialize_object'):
snapshots['postchange'] = instance.serialize_object()
+2 -1
View File
@@ -121,7 +121,8 @@ class ChangeLoggingMixin(DeleteMixin, models.Model):
if hasattr(self, '_prechange_snapshot'):
objectchange.prechange_data = self._prechange_snapshot
if action in (ObjectChangeActionChoices.ACTION_CREATE, ObjectChangeActionChoices.ACTION_UPDATE):
objectchange.postchange_data = self.serialize_object(exclude=exclude)
self._postchange_snapshot = self.serialize_object(exclude=exclude)
objectchange.postchange_data = self._postchange_snapshot
return objectchange