Skip to content

Commit

Permalink
Fix for Issue jazzband#260
Browse files Browse the repository at this point in the history
  • Loading branch information
Liamhanninen committed Sep 6, 2020
1 parent c3b0604 commit 0381b47
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/auditlog/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 0381b47

Please sign in to comment.