|
14 | 14 | get_current_user |
15 | 15 | from easyaudit.models import CRUDEvent |
16 | 16 | from easyaudit.settings import REGISTERED_CLASSES, UNREGISTERED_CLASSES, \ |
17 | | - WATCH_MODEL_EVENTS, CRUD_DIFFERENCE_CALLBACKS |
| 17 | + WATCH_MODEL_EVENTS, CRUD_DIFFERENCE_CALLBACKS,\ |
| 18 | + CRUD_OBJECT_JSON_REPR_SERIALIZER_OVERRIDE |
18 | 19 | from easyaudit.utils import model_delta |
19 | 20 |
|
20 | 21 | logger = logging.getLogger(__name__) |
@@ -53,7 +54,10 @@ def pre_save(sender, instance, raw, using, update_fields, **kwargs): |
53 | 54 | if not should_audit(instance): |
54 | 55 | return False |
55 | 56 | try: |
56 | | - object_json_repr = serializers.serialize("json", [instance]) |
| 57 | + if CRUD_OBJECT_JSON_REPR_SERIALIZER_OVERRIDE != None: |
| 58 | + object_json_repr = CRUD_OBJECT_JSON_REPR_SERIALIZER_OVERRIDE(instance) |
| 59 | + else: |
| 60 | + object_json_repr = serializers.serialize("json", [instance]) |
57 | 61 | except Exception: |
58 | 62 | # We need a better way for this to work. ManyToMany will fail on pre_save on create |
59 | 63 | return None |
@@ -122,7 +126,11 @@ def post_save(sender, instance, created, raw, using, update_fields, **kwargs): |
122 | 126 | with transaction.atomic(): |
123 | 127 | if not should_audit(instance): |
124 | 128 | return False |
125 | | - object_json_repr = serializers.serialize("json", [instance]) |
| 129 | + |
| 130 | + if CRUD_OBJECT_JSON_REPR_SERIALIZER_OVERRIDE != None: |
| 131 | + object_json_repr = CRUD_OBJECT_JSON_REPR_SERIALIZER_OVERRIDE(instance) |
| 132 | + else: |
| 133 | + object_json_repr = serializers.serialize("json", [instance]) |
126 | 134 |
|
127 | 135 | # created or updated? |
128 | 136 | if created: |
|
0 commit comments