Skip to content

Commit d1024a4

Browse files
committed
doc(): documenting custom history columns + changelog
1 parent 9f6d7e1 commit d1024a4

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

AUTHORS.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Authors
3636
- vnagendra
3737
- Lucas Wiman
3838
- Michael England
39+
- Gregory Bataille
3940

4041
Background
4142
==========

CHANGES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Changes
44
tip (unreleased)
55
----------------
66
- Added --batchsize option to the populate_history management command.
7+
- Add the ability to display object attributes in the history list view to see
8+
what has changed easily
79

810
1.8.2 (2017-01-19)
911
------------------

docs/usage.rst

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,36 @@ An example of admin integration for the ``Poll`` and ``Choice`` models:
127127
Changing a history-tracked model from the admin interface will automatically record the user who made the change (see :doc:`/advanced`).
128128

129129

130+
Displaying custom columns in the admin history list view
131+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
132+
133+
By default, the history log displays one line per change containing
134+
135+
* a link to the detail of the object at that point in time
136+
* the date and time the object was changed
137+
* a comment corresponding to the change
138+
* the author of the change
139+
140+
You can add other columns (for example the object's status if it has one to see
141+
how it evolved) by adding a ``history_list_display`` array of fields to the
142+
admin class
143+
144+
.. code-block:: python
145+
146+
from django.contrib import admin
147+
from simple_history.admin import SimpleHistoryAdmin
148+
from .models import Poll, Choice
149+
150+
151+
class PollHistoryAdmin(SimpleHistoryAdmin):
152+
list_display = ["id", "name", "status"]
153+
history_list_display = ["status"]
154+
search_fields = ['name', 'user__username']
155+
156+
admin.site.register(Poll, PollHistoryAdmin)
157+
admin.site.register(Choice, SimpleHistoryAdmin)
158+
159+
130160
Querying history
131161
----------------
132162

0 commit comments

Comments
 (0)