-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(history): add basic doc for new history plugin
- Loading branch information
Showing
3 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
History plugin | ||
============== | ||
|
||
The :py:mod:`apis_core.history` module provides versioning | ||
to the APIS framework. It is based on the `django-simple-history`_ | ||
package. | ||
|
||
VersionMixin | ||
------------ | ||
|
||
The :py:class:`apis_core.history.models.VersionMixin` class is a mixin | ||
that can be added to any model to enable versioning. It adds a `history` | ||
property to the model that returns a `HistoricalRecords` instance. Additionally | ||
it allows to override the date of the revision by setting the `_history_date` | ||
property of the model instance. | ||
To activate versioning for a model, simply inherit from `VersionMixin`: | ||
```python | ||
from django.db import models | ||
from apis_core.apis_history.models import VersionMixin | ||
class MyModel(VersionMixin, models.Model): | ||
pass | ||
``` | ||
|
||
API endpoint | ||
------------ | ||
|
||
The :py:class:`apis_core.history.api_views.GenericHistoryLogs` class is a viewset | ||
that provides a REST API endpoint for the version history of a model. It can be | ||
used to retrieve the version history of a model instance. | ||
The viewset can be accessed under `/apis/api/history/entity/edit_log/`. It takes | ||
two mandatory query parameters: `id` and `entity_type`. The `id` parameter is the | ||
primary key of the model instance and the `entity_type` parameter is the name of | ||
the model class. The viewset returns a list of historical revisions of the model | ||
instance. It is also included in the `apis_core` API schema. The swagger documentation | ||
can be accessed under `/apis/swagger/schema/swagger-ui/#/apis/apis_api_history_entity_edit_log_list`. | ||
|
||
|
||
.. _django-simple-history: https://django-simple-history.readthedocs.io/en/latest/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters