diff --git a/auditlog/models.py b/auditlog/models.py index e073c882..2c160d75 100644 --- a/auditlog/models.py +++ b/auditlog/models.py @@ -15,6 +15,7 @@ from django.db.models import Q, QuerySet from django.utils import formats from django.utils.encoding import smart_str +from django.utils.text import Truncator from django.utils.translation import gettext_lazy as _ from auditlog.diff import mask_str @@ -464,6 +465,19 @@ def changes_display_dict(self): except AttributeError: # if the field is a relationship it has no internal type and exclude it continue + + if field_type == "ManyToManyField": + values_display = values + values_display["objects"] = [ + f"{Truncator(i).chars(140,html=True)}..." if len(i) > 140 else i + for i in values["objects"] + ] + verbose_name = model_fields["mapping_fields"].get( + field.name, getattr(field, "verbose_name", field.name) + ) + changes_display_dict[verbose_name] = values_display + continue + for value in values: # handle case where field is a datetime, date, or time type if field_type in ["DateTimeField", "DateField", "TimeField"]: @@ -481,7 +495,8 @@ def changes_display_dict(self): pass # check if length is longer than 140 and truncate with ellipsis if len(value) > 140: - value = f"{value[:140]}..." + # value = f"{value[:140]}..." + value = f"{Truncator(value).chars(140,html=True)}..." values_display.append(value) verbose_name = model_fields["mapping_fields"].get(