Restructure change iterator.

This commit is contained in:
Marco Marra 2026-01-28 14:27:23 +01:00
parent 7a7e3d04ab
commit 42b4ea5cb4

View file

@ -433,28 +433,23 @@ class AbstractLogEntry(models.Model):
"""
substrings = []
if all(
isinstance(value, (list, tuple)) and len(value) == 2
for value in self.changes_dict.values()
):
substrings = [
"{field_name:s}{colon:s}{old:s}{arrow:s}{new:s}".format(
for field, value in sorted(self.changes_dict.items()):
if isinstance(value, (list, tuple)) and len(value) == 2:
# handle regular field change
substring = "{field_name:s}{colon:s}{old:s}{arrow:s}{new:s}".format(
field_name=field,
colon=colon,
old=values[0],
old=value[0],
arrow=arrow,
new=values[1],
new=value[1],
)
for field, values in sorted(self.changes_dict.items())
]
elif all(
isinstance(value, dict) and value.get("type") == "m2m"
for value in self.changes_dict.values()
):
substrings = [
f"{field}{colon}{value_dict['operation']} {sorted(value_dict['objects'])}"
for field, value_dict in self.changes_dict.items()
]
substrings.append(substring)
elif isinstance(value, dict) and value.get("type") == "m2m":
# handle m2m change
substring = (
f"{field}{colon}{value['operation']} {sorted(value['objects'])}"
)
substrings.append(substring)
return separator.join(substrings)