Skip to content

Commit 71d3bd6

Browse files
committed
Add documentation for inheritable tracking
1 parent d6ce5c9 commit 71d3bd6

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

CHANGES.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
Changes
22
=======
33

4+
tip (unreleased)
5+
----------------
6+
- History tracking can be inherited by passing `inherit=True`. (gh-63)
7+
48
1.7.0 (2015-12-02)
59
------------------
610
- Add ability to list history in admin when the object instance is deleted. (gh-72)

docs/advanced.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,35 @@ third-party apps you don't have control over. Here's an example of using
6565
register(User)
6666
6767
68+
Allow tracking to be inherited
69+
---------------------------------
70+
71+
By default history tracking is only added for the model that is passed
72+
to ``register()`` or has the ``HistoricalRecords`` descriptor. By
73+
passing ``inherit=True`` to either way of registering you can change
74+
that behavior so that any child model inheriting from it will have
75+
historical tracking as well. Be careful though, in cases where a model
76+
can be tracked more than once, ``MultipleRegistrationsError`` will be
77+
raised.
78+
79+
.. code-block:: python
80+
81+
from django.contrib.auth.models import User
82+
from django.db import models
83+
from simple_history import register
84+
from simple_history.models import HistoricalRecords
85+
86+
# register() example
87+
register(User, inherit=True)
88+
89+
# HistoricalRecords example
90+
class Poll(models.Model):
91+
history = HistoricalRecords(inherit=True)
92+
93+
Both ``User`` and ``Poll`` in the example above will cause any model
94+
inheriting from them to have historical tracking as well.
95+
96+
6897
.. recording_user:
6998
7099
Recording Which User Changed a Model

0 commit comments

Comments
 (0)