diff --git a/AUTHORS.rst b/AUTHORS.rst index fcf285f71..dafe83de3 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -39,6 +39,7 @@ Authors - David Grochowski (`ThePumpingLemma `_) - David Hite - David Smith +- David Toulmin (`davidtoulmin `_) - `ddabble `_ - Dmytro Shyshov (`xahgmah `_) - Edouard Richard (`vied12 ` _) diff --git a/CHANGES.rst b/CHANGES.rst index 049e39f75..c2ec0ebf2 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -16,6 +16,7 @@ Unreleased version is lower than 4.2 (gh-1261) - Small performance optimization of the ``clean-duplicate_history`` command (gh-1015) - Support Simplified Chinese translation (gh-1281) +- Added a running diff to the _object_history_list.html so users can see a list of all field changes made in each change 3.4.0 (2023-08-18) ------------------ diff --git a/simple_history/admin.py b/simple_history/admin.py index 34e3033fe..820ab9bf6 100644 --- a/simple_history/admin.py +++ b/simple_history/admin.py @@ -70,6 +70,15 @@ def history_view(self, request, object_id, extra_context=None): for list_entry in action_list: setattr(list_entry, history_list_entry, value_for_entry(list_entry)) + previous = None + for list_entry in reversed(action_list): + if previous: + value = list_entry.diff_against(previous).changes + else: + value = "" + setattr(list_entry, "diff", value) + previous = list_entry + content_type = self.content_type_model_cls.objects.get_for_model( get_user_model() ) diff --git a/simple_history/templates/simple_history/_object_history_list.html b/simple_history/templates/simple_history/_object_history_list.html index 0dd575cc5..aa2ceffb2 100644 --- a/simple_history/templates/simple_history/_object_history_list.html +++ b/simple_history/templates/simple_history/_object_history_list.html @@ -10,6 +10,7 @@ {% for column in history_list_display %} {% trans column %} {% endfor %} + {% trans 'Changes from previous' %} {% trans 'Date/time' %} {% trans 'Comment' %} {% trans 'Changed by' %} @@ -21,8 +22,9 @@ {{ action.history_object }} {% for column in history_list_display %} - {{ action|getattribute:column }} + {{ action|getattribute:column }} {% endfor %} + {% include "simple_history/diff_table.html" with diff=action.diff %} {{ action.history_date }} {{ action.get_history_type_display }} diff --git a/simple_history/templates/simple_history/diff_table.html b/simple_history/templates/simple_history/diff_table.html new file mode 100644 index 000000000..33c0ad4d2 --- /dev/null +++ b/simple_history/templates/simple_history/diff_table.html @@ -0,0 +1,21 @@ +{% load i18n %} +{% if diff %} + + + + + + + + {% for change in diff %} + + + + + + {% endfor %} + +
{% trans 'Field' %}{% trans 'Old Value' %}{% trans 'New Value' %}
{{ change.field }}{{ change.old }}{{ change.new }}
+{% else %} +{% trans 'No Change' %} +{% endif %}