@@ -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
@@ -158,3 +187,29 @@ To change the auto-generated HistoricalRecord models base class from
158187 pub_date = models.DateTimeField(' date published' )
159188 changed_by = models.ForeignKey(' auth.User' )
160189 history = HistoricalRecords(bases = [RoutableModel])
190+
191+ Custom history table name
192+ -------------------------
193+
194+ By default, the table name for historical models follow the Django convention
195+ and just add ``historical `` before model name. For instance, if your application
196+ name is ``polls `` and your model name ``Question ``, then the table name will be
197+ ``polls_historicalquestion ``.
198+
199+ You can use the ``table_name `` parameter with both ``HistoricalRecords() `` or
200+ ``register() `` to change this behavior.
201+
202+ .. code-block :: python
203+
204+ class Question (models .Model ):
205+ question_text = models.CharField(max_length = 200 )
206+ pub_date = models.DateTimeField(' date published' )
207+ history = HistoricalRecords(table_name = ' polls_question_history' )
208+
209+ .. code-block :: python
210+
211+ class Question (models .Model ):
212+ question_text = models.CharField(max_length = 200 )
213+ pub_date = models.DateTimeField(' date published' )
214+
215+ register(Question, table_name = ' polls_question_history' )
0 commit comments