A Django utility to track changes to model instances and save the history of updates.
Project description
Django Model History Tracker
Django Model History Tracker is a utility that tracks changes to model instances and saves the history of updates. This can be helpful for auditing purposes or for generating reports about changes over time.
Features
- Track creation, update, and deletion of model instances
- Store historical data in a separate
Historymodel - Easy integration with existing Django models using a mixin
Installation
- Install the package using pip:
pip install django-model-history-tracker
- Add
'django_model_history_tracker'to yourINSTALLED_APPSinsettings.py:
INSTALLED_APPS = [
...
'django_model_history_tracker',
...
]
python manage.py migrate
## Usage
To use Django Model History Tracker, simply inherit the HistoryTrackerMixin in any model you want to track:
from django.db import models
from django_model_history_tracker.mixins import HistoryTrackerMixin
class ExampleModel(HistoryTrackerMixin, models.Model):
field1 = models.CharField(max_length=100)
field2 = models.IntegerField()
That's it! Your model will now automatically track changes and store them in the History model.
Accessing History
You can access the history of a tracked model instance using the generic relation:
history = example_model_instance.history_set.all()
Each history entry will have the following fields:
action: The action that occurred ('create', 'update', or 'delete')
timestamp: The timestamp of when the action occurred
changes: A JSON field containing the changes made to the instance
Contributing
Contributions are welcome! Please feel free to submit issues or pull requests on the GitHub repository.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django-model-history-tracker-0.2.tar.gz.
File metadata
- Download URL: django-model-history-tracker-0.2.tar.gz
- Upload date:
- Size: 3.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
22090f3e40ac2ca1834fc79b3ce60ca3ba715b68fa12b47f100525fa5f8fcb9a
|
|
| MD5 |
5c98d637162f8081869b3d67b09004ef
|
|
| BLAKE2b-256 |
d38fb7cf359de3a9aa0064140222517a18db33295ee9f4a2ea4ebb47646be65f
|
File details
Details for the file django_model_history_tracker-0.2-py3-none-any.whl.
File metadata
- Download URL: django_model_history_tracker-0.2-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
718de663232430daa87d6599815add1829929208c9f1118d0ff13fb6ae3bf380
|
|
| MD5 |
b88933e0852b9f86ba6275fcf13ff0cf
|
|
| BLAKE2b-256 |
d3aad4555aa7a5398adac1fabd4752108efc52544330f9235254f936b4ed53e9
|