mirror of
https://github.com/jazzband/django-auditlog.git
synced 2026-03-16 22:20:26 +00:00
Add changes_dict and changes_str utility methods to LogEntry model
This commit is contained in:
parent
8c541fe416
commit
f5aed059bf
1 changed files with 23 additions and 0 deletions
|
|
@ -99,6 +99,29 @@ class LogEntry(models.Model):
|
|||
fstring = _("Logged {repr:s}")
|
||||
|
||||
return fstring.format(repr=self.object_repr)
|
||||
|
||||
@property
|
||||
def changes_dict(self):
|
||||
try:
|
||||
return json.loads(self.changes)
|
||||
except ValueError:
|
||||
return {}
|
||||
|
||||
@property
|
||||
def changes_str(self, colon=': ', arrow=u' \u2192 ', separator='; '):
|
||||
substrings = []
|
||||
|
||||
for field, values in self.changes_dict.iteritems():
|
||||
substring = u'{fieldname:s}{colon:s}{old:s}{arrow:s}{new:s}'.format(
|
||||
fieldname=field,
|
||||
colon=colon,
|
||||
old=values[0],
|
||||
arrow=arrow,
|
||||
new=values[1],
|
||||
)
|
||||
substrings.append(substring)
|
||||
|
||||
return separator.join(substrings)
|
||||
|
||||
|
||||
class AuditlogHistoryField(generic.GenericRelation):
|
||||
|
|
|
|||
Loading…
Reference in a new issue