Skip to content

Commit 11fa04a

Browse files
author
Ross Mechanic
authored
GH-221: Added reserved names to docs (#523)
1 parent 7afa08a commit 11fa04a

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

docs/common_issues.rst

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,47 @@ historical model tries to insert using the ``F()`` expression, and raises a
112112
``ValueError``.
113113

114114
.. _here: https://docs.djangoproject.com/en/2.0/ref/models/expressions/#f-expressions
115+
116+
117+
Reserved Field Names
118+
--------------------
119+
120+
For each base model that has its history tracked using ``django-simple-history``,
121+
an associated historical model is created. Thus, if we have:
122+
123+
.. code-block:: python
124+
125+
class BaseModel(models.Model):
126+
history = HistoricalRecords()
127+
128+
a Django model called ``HistoricalBaseModel`` is also created with all of the fields
129+
from ``BaseModel``, plus a few extra fields and methods that are on all historical models.
130+
131+
Since these fields and methods are on all historical models, any field or method names
132+
on a base model that clash with those names will not be on the historical model (and,
133+
thus, won't be tracked). The reserved historical field and method names are below:
134+
135+
- ``history_id``
136+
- ``history_date``
137+
- ``history_change_reason``
138+
- ``history_type``
139+
- ``history_object``
140+
- ``history_user``
141+
- ``history_user_id``
142+
- ``instance``
143+
- ``instance_type``
144+
- ``next_record``
145+
- ``prev_record``
146+
- ``revert_url``
147+
- ``__str__``
148+
149+
So if we have:
150+
151+
.. code-block:: python
152+
153+
class BaseModel(models.Model):
154+
instance = models.CharField(max_length=255)
155+
history = HistoricalRecords()
156+
157+
the ``instance`` field will not actually be tracked on the history table because it's
158+
in the reserved set of terms.

0 commit comments

Comments
 (0)