Skip to content

Commit 45d6f8e

Browse files
author
Ross Mechanic
authored
Initial reorg of docs (#510)
* Initial cut for cleaning up docs * Second run-through for updated docs * Updated index file * Fixed typo
1 parent 32e6289 commit 45d6f8e

14 files changed

+778
-714
lines changed

CONTRIBUTING.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ In order to add translations, refer to Django's `translation docs`_ and follow t
8282
steps:
8383

8484
1. Ensure that Django is installed
85-
2. Invoke ``django-admin makemessages -l <LOCALE NAME> in the repository's root
85+
2. Invoke ``django-admin makemessages -l <LOCALE NAME>`` in the repository's root
8686
directory.
8787
3. Add translations to the created
8888
``simple_history/locale/<LOCALE NAME>/LC_MESSAGES/django.po`` file.

README.rst

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,13 @@ Getting Help
4747

4848
Documentation is available at https://django-simple-history.readthedocs.io/
4949

50-
Issue tracker is at https://github.com/treyhunner/django-simple-history/issues
51-
52-
Pull requests are welcome. Read the CONTRIBUTING file for tips on
50+
Pull requests are welcome. Read the `CONTRIBUTING`_ file for tips on
5351
submitting a pull request.
5452

55-
.. _PyPI: https://pypi.python.org/pypi/django-email-log/
53+
.. _CONTRIBUTING: https://github.com/treyhunner/django-simple-history/blob/master/CONTRIBUTING.rst
54+
55+
License
56+
-------
57+
58+
This project is licensed under the
59+
`BSD 3-Clause license <https://choosealicense.com/licenses/bsd-3-clause/>`_.

docs/admin.rst

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
Admin Integration
2+
-----------------
3+
4+
To allow viewing previous model versions on the Django admin site, inherit from
5+
the ``simple_history.admin.SimpleHistoryAdmin`` class when registering your
6+
model with the admin site.
7+
8+
This will replace the history object page on the admin site and allow viewing
9+
and reverting to previous model versions. Changes made in admin change forms
10+
will also accurately note the user who made the change.
11+
12+
.. image:: screens/1_poll_history.png
13+
14+
Clicking on an object presents the option to revert to that version of the object.
15+
16+
.. image:: screens/2_revert.png
17+
18+
(The object is reverted to the selected state)
19+
20+
.. image:: screens/3_poll_reverted.png
21+
22+
Reversions like this are added to the history.
23+
24+
.. image:: screens/4_history_after_poll_reverted.png
25+
26+
An example of admin integration for the ``Poll`` and ``Choice`` models:
27+
28+
.. code-block:: python
29+
30+
from django.contrib import admin
31+
from simple_history.admin import SimpleHistoryAdmin
32+
from .models import Poll, Choice
33+
34+
admin.site.register(Poll, SimpleHistoryAdmin)
35+
admin.site.register(Choice, SimpleHistoryAdmin)
36+
37+
Changing a history-tracked model from the admin interface will automatically record the user who made the change (see :doc:`/user_tracking`).
38+
39+
40+
Displaying custom columns in the admin history list view
41+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
42+
43+
By default, the history log displays one line per change containing
44+
45+
* a link to the detail of the object at that point in time
46+
* the date and time the object was changed
47+
* a comment corresponding to the change
48+
* the author of the change
49+
50+
You can add other columns (for example the object's status to see
51+
how it evolved) by adding a ``history_list_display`` array of fields to the
52+
admin class
53+
54+
.. code-block:: python
55+
56+
from django.contrib import admin
57+
from simple_history.admin import SimpleHistoryAdmin
58+
from .models import Poll, Choice
59+
60+
61+
class PollHistoryAdmin(SimpleHistoryAdmin):
62+
list_display = ["id", "name", "status"]
63+
history_list_display = ["status"]
64+
search_fields = ['name', 'user__username']
65+
66+
admin.site.register(Poll, PollHistoryAdmin)
67+
admin.site.register(Choice, SimpleHistoryAdmin)
68+
69+
70+
.. image:: screens/5_history_list_display.png

docs/reference.rst renamed to docs/common_issues.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ Common Issues
33

44
Bulk Creating and Queryset Updating
55
-----------------------------------
6-
Django Simple History functions by saving history using a ``post_save`` signal
6+
``django-simple-history`` functions by saving history using a ``post_save`` signal
77
every time that an object with history is saved. However, for certain bulk
88
operations, such as bulk_create_ and `queryset updates <https://docs.djangoproject.com/en/2.0/ref/models/querysets/#update>`_,
99
signals are not sent, and the history is not saved automatically. However,
10-
Django Simple History provides utility functions to work around this.
10+
``django-simple-history`` provides utility functions to work around this.
1111

1212
Bulk Creating a Model with History
1313
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
14-
As of Django Simple History 2.2.0, we can use the utility function
14+
As of ``django-simple-history`` 2.2.0, we can use the utility function
1515
``bulk_create_with_history`` in order to bulk create objects while saving their
1616
history:
1717

@@ -63,7 +63,6 @@ As the Django documentation says::
6363
.. _queryset updates: https://docs.djangoproject.com/en/2.0/ref/models/querysets/#update
6464

6565

66-
6766
Tracking Custom Users
6867
---------------------
6968

0 commit comments

Comments
 (0)