mirror of
https://github.com/jazzband/django-auditlog.git
synced 2026-03-16 22:20:26 +00:00
some util functions
This commit is contained in:
parent
1a0959d8ab
commit
19291f54d9
1 changed files with 14 additions and 0 deletions
|
|
@ -1,3 +1,5 @@
|
|||
import json
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.contenttypes import generic
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
|
|
@ -40,6 +42,11 @@ class LogEntryManager(models.Manager):
|
|||
|
||||
return self.create(**kwargs)
|
||||
return None
|
||||
|
||||
def get_entries_from_model(self, model):
|
||||
content_type = ContentType.objects.get_for_model(model)
|
||||
object_id = model.pk
|
||||
return self.get_query_set().filter(content_type=content_type, object_id=object_id)
|
||||
|
||||
|
||||
class LogEntry(models.Model):
|
||||
|
|
@ -93,6 +100,13 @@ class LogEntry(models.Model):
|
|||
|
||||
return fstring.format(repr=self.object_repr)
|
||||
|
||||
def html_formated_changes(self):
|
||||
changes_result = []
|
||||
changes_dict = json.loads(self.changes.encode('utf-8'))
|
||||
for field, changes in changes_dict.items():
|
||||
changes_result.append('<strong>%s</strong> from %s <strong>to</strong> %s' % (field, changes[0], changes[1]))
|
||||
return changes_result
|
||||
|
||||
|
||||
class AuditLogHistoryField(generic.GenericRelation):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Reference in a new issue