-
Notifications
You must be signed in to change notification settings - Fork 32
Open
Description
I try to get object change using following code, but MutableJSON has no history getted
def get_object_changes(obj):
"""Given a model instance, returns dict of pending
changes waiting for database flush/commit.
e.g. {
"pre_change": {},
"post_change": {},
"diff": {}
}
"""
inspection = inspect(obj)
changes = {
"pre_change": {},
"post_change": {},
"diff": {},
}
for attr in class_mapper(obj.__class__).column_attrs:
if getattr(inspection.attrs, attr.key).history.has_changes():
if get_history(obj, attr.key)[2]:
before = get_history(obj, attr.key)[2].pop()
after = getattr(obj, attr.key)
changes["pre_change"][attr.key] = before
changes["post_change"][attr.key] = after
if before != after:
if before or after:
changes["diff"][attr.key] = {"before": before, "after": after}
return jsonable_encoder(changes)Metadata
Metadata
Assignees
Labels
No labels