all_history = atr.history.all().order_by('-date_updated')
for new_record, old_record in zip(all_history, all_history[1:]):
print('new_record date updated', new_record.date_updated)
print('old_record date updated', old_record.date_updated)
delta = new_record.diff_against(old_record)
for change in delta.changes:
print(f"'{change.field}' changed from '{change.old}' to '{change.new}'")
print('---')
all_history = atr.history.all()
for new_record, old_record in zip(all_history, all_history[1:]):
print('new_record date updated', new_record.date_updated)
print('old_record date updated', old_record.date_updated)
delta = new_record.diff_against(old_record)
for change in delta.changes:
print(f"'{change.field}' changed from '{change.old}' to '{change.new}'")
print('---')
def print_history_changes(obj):
history = obj.history.order_by('history_date')
fields = [f.name for f in obj._meta.fields]
for i in range(1, len(history)):
old = history[i-1]
new = history[i]
print(f"\n--- Change at: {new.history_date} by {new.history_user} ---")
for field in fields:
old_val = getattr(old, field)
new_val = getattr(new, field)
if old_val != new_val:
print(f"{field}: {str(old_val)} → {str(new_val)}")