Skip to content

Commit 1af548b

Browse files
author
Ross Mechanic
authored
Added docs for reverting a model (#377)
1 parent 806d1d1 commit 1af548b

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

docs/usage.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,3 +237,27 @@ If you have a historical record for an instance and would like to retrieve the p
237237
<HistoricalPoll: Poll object as of 2010-10-25 18:04:13.814128>
238238
239239
If a historical record is the first record, `prev_record` will be `None`. Similarly, if it is the latest record, `next_record` will be `None`
240+
241+
Reverting the Model
242+
~~~~~~~~~~~~~~~~~~~
243+
244+
``SimpleHistoryAdmin`` allows users to revert back to an old version of the
245+
model through the admin interface. You can also do this programmatically. To
246+
do so, you can take any historical object, and save the associated instance.
247+
For example, if we want to access the earliest ``HistoricalPoll``, for an
248+
instance of ``Poll``, we can do:
249+
250+
.. code-block:: pycon
251+
252+
>>> poll.history.earliest()
253+
<HistoricalPoll: Poll object as of 2010-10-25 18:04:13.814128>
254+
255+
And to revert to that ``HistoricalPoll`` instance, we can do:
256+
257+
.. code-block:: pycon
258+
>>> earliest_poll = poll.history.earliest()
259+
>>> earliest_poll.instance.save()
260+
261+
This will change the ``poll`` instance to have the data from the
262+
``HistoricalPoll`` object and it will create a new row in the
263+
``HistoricalPoll`` table indicating that a new change has been made.

0 commit comments

Comments
 (0)