skip using foreign key to construct and display diff of foreign key fields

This commit is contained in:
fabianallendorf 2025-11-05 15:40:22 +01:00
parent 57604a6069
commit 37b3ba20bd
2 changed files with 9 additions and 1 deletions

View file

@ -106,7 +106,11 @@ def get_field_value(obj, field, use_json_for_changes=False):
value = json.dumps(value, sort_keys=True, cls=field.encoder)
except TypeError:
pass
elif (field.one_to_one or field.many_to_one) and hasattr(field, "rel_class"):
elif (
not settings.AUDITLOG_USE_STRING_REPRESENTATION_IN_FOREIGN_KEY_CHANGES
and (field.one_to_one or field.many_to_one)
and hasattr(field, "rel_class")
):
value = smart_str(getattr(obj, field.get_attname()), strings_only=True)
else:
value = getattr(obj, field.name)

View file

@ -542,6 +542,10 @@ class AbstractLogEntry(models.Model):
"""
:return: A string representing a given FK value and the field to which it belongs
"""
# Return value if FK value should explicitly be interpreted as string representation
if settings.AUDITLOG_USE_STRING_REPRESENTATION_IN_FOREIGN_KEY_CHANGES:
return value
# Return "None" if the FK value is "None".
if value == "None":
return value