Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix changes_display_dict to display added/deleted objects for m2m updates #464

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion auditlog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"]:
Expand All @@ -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(
Expand Down