Skip to content

Commit

Permalink
Added support for a model delta callback
Browse files Browse the repository at this point in the history
  • Loading branch information
jdkizer9 committed Jun 5, 2019
1 parent 6f1bb68 commit c9e01f9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion easyaudit/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,6 @@ def get_model_list(class_list):
REQUEST_EVENT_LIST_FILTER = getattr(settings, 'DJANGO_EASY_AUDIT_REQUEST_EVENT_LIST_FILTER', ['method', 'user', 'datetime', ])

# JSON object representation serializer override
CRUD_OBJECT_JSON_REPR_SERIALIZER_OVERRIDE = getattr(settings, 'DJANGO_EASY_AUDIT_CRUD_OBJECT_JSON_REPR_SERIALIZER_OVERRIDE', None)
CRUD_OBJECT_JSON_REPR_SERIALIZER_OVERRIDE = getattr(settings, 'DJANGO_EASY_AUDIT_CRUD_OBJECT_JSON_REPR_SERIALIZER_OVERRIDE', None)

CRUD_OBJECT_MODEL_DELTA_CALLBACK = getattr(settings, 'DJANGO_EASY_AUDIT_CRUD_OBJECT_MODEL_DELTA_CALLBACK', None)
4 changes: 3 additions & 1 deletion easyaudit/signals/model_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from easyaudit.models import CRUDEvent
from easyaudit.settings import REGISTERED_CLASSES, UNREGISTERED_CLASSES, \
WATCH_MODEL_EVENTS, CRUD_DIFFERENCE_CALLBACKS,\
CRUD_OBJECT_JSON_REPR_SERIALIZER_OVERRIDE
CRUD_OBJECT_JSON_REPR_SERIALIZER_OVERRIDE, CRUD_OBJECT_MODEL_DELTA_CALLBACK
from easyaudit.utils import model_delta

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -71,6 +71,8 @@ def pre_save(sender, instance, raw, using, update_fields, **kwargs):
if not created:
old_model = sender.objects.get(pk=instance.pk)
delta = model_delta(old_model, instance)
if CRUD_OBJECT_MODEL_DELTA_CALLBACK != None:
delta = CRUD_OBJECT_MODEL_DELTA_CALLBACK(old_model, instance, delta)
changed_fields = json.dumps(delta)
event_type = CRUDEvent.UPDATE

Expand Down

0 comments on commit c9e01f9

Please sign in to comment.