1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Moved object serialization into a utility function

This commit is contained in:
Jeremy Stretch
2018-06-22 14:00:23 -04:00
parent 9d419de9dc
commit 6c1b5fdf3a
3 changed files with 17 additions and 11 deletions

View File

@@ -1,11 +1,9 @@
from __future__ import unicode_literals
import json
from django.core.serializers import serialize
from django.db import models
from extras.models import ObjectChange
from utilities.utils import serialize_object
class ChangeLoggedModel(models.Model):
@@ -32,15 +30,10 @@ class ChangeLoggedModel(models.Model):
Create a new ObjectChange representing a change made to this object. This will typically be called automatically
by extras.middleware.ChangeLoggingMiddleware.
"""
# Serialize the object using Django's built-in JSON serializer, then extract only the `fields` dict.
json_str = serialize('json', [self])
object_data = json.loads(json_str)[0]['fields']
ObjectChange(
user=user,
request_id=request_id,
changed_object=self,
action=action,
object_data=object_data
object_data=serialize_object(self)
).save()