From 0381b47acc6bf971f1172b8e93f4f5b2319ab36c Mon Sep 17 00:00:00 2001 From: Liam Hanninen Date: Sun, 6 Sep 2020 10:53:53 -0400 Subject: [PATCH 1/2] Fix for Issue #260 --- src/auditlog/diff.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/auditlog/diff.py b/src/auditlog/diff.py index 9f996f60..2d221327 100644 --- a/src/auditlog/diff.py +++ b/src/auditlog/diff.py @@ -2,7 +2,7 @@ from django.conf import settings from django.core.exceptions import ObjectDoesNotExist -from django.db.models import Model, NOT_PROVIDED, DateTimeField +from django.db.models import Model, NOT_PROVIDED, DateTimeField, DecimalField from django.utils import timezone from django.utils.encoding import smart_text @@ -73,6 +73,12 @@ def get_field_value(obj, field): value = timezone.make_naive(value, timezone=timezone.utc) except ObjectDoesNotExist: value = field.default if field.default is not NOT_PROVIDED else None + elif isinstance(field, DecimalField): + # Fix for Issue #260 + # DecimalFields can be stored with multiple zeroes after decimal but + # might only have one zero after save() method, so we need to remove + # all extra zeroes for an accurate comparison. + value = smart_text(getattr(obj, field.name, None)).rstrip('0').rstrip('.') else: try: value = smart_text(getattr(obj, field.name, None)) From e3d389234c4398981e1dddbac01ad97813852b2d Mon Sep 17 00:00:00 2001 From: Liam Hanninen Date: Sun, 6 Sep 2020 11:13:21 -0400 Subject: [PATCH 2/2] Fix for Issue #260 --- src/auditlog/diff.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/auditlog/diff.py b/src/auditlog/diff.py index 2d221327..31340d75 100644 --- a/src/auditlog/diff.py +++ b/src/auditlog/diff.py @@ -78,7 +78,8 @@ def get_field_value(obj, field): # DecimalFields can be stored with multiple zeroes after decimal but # might only have one zero after save() method, so we need to remove # all extra zeroes for an accurate comparison. - value = smart_text(getattr(obj, field.name, None)).rstrip('0').rstrip('.') + value_before_clean = smart_text(getattr(obj, field.name, None)) + value = value_before_clean.rstrip('0').rstrip('.') if '.' in value_before_clean else value_before_clean else: try: value = smart_text(getattr(obj, field.name, None))