django-model-auditor
django-model-auditor is a Python library for maintaining versions of your django model instances.
Installation
Use the package manager pip to install foobar.
pip install django-model-auditor
Usage
- Add audits in INSTALLED_APPS inside settings.py of your django project
INSTALLED_APPS = [
'audits.apps.AuditsConfig',
]
- run migration to create auditlog model
python manage.py migrate
- Change metaclass of model(for which audit logs are needed) to ModelHistoryMeta
from audits.models import ModelHistoryMeta
from django.db import models
class ExampleModel(models.Model, metaclass=ModelHistoryMeta):
field1 = models.CharField(max_length=100)
field2 = models.CharField(max_length=100)
- Example
import ExampleModel
object = ExampleModel(field1="foo", field2="bar")
object.save() #will create an entry in auditlog model
object.field1 = "Foo"
object.field2 = "Bar"
object.save() #will create another entry in auditlog model
object.field1 = "FOO"
object.field2 = "BAR"
object.save() #will create another entry in auditlog model
#To get previous versions of the object
previous_versions = AuditLog.get_prev_versions(object, limit=2)
#By default get_prev_versions return only last_prev_version to
#get more versions we need to specify limit
latest_prev_version = previous_versions[0]
print("%s %s"%(latest_prev_version.field1, latest_prev_version.field2)) # "Foo","Bar"
prev_to_prev_version = previous_versions[1]
print("%s %s"%(prev_to_prev_version.field1, prev_to_prev_version.field2)) # "foo","bar"
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
License
Release files for django-model-auditor 0.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| django-model-auditor-0.0.4.tar.gz | 3.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_model_auditor-0.0.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.3 kB
Release files / django-model-auditor-0.0.4.tar.gz
| Download URL | django-model-auditor-0.0.4.tar.gz |
|---|---|
| Size | 3.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0b0c31b6d92949c0c25fd3459f7e3dd44bf33f76842054b443179c45cf0d1215
|
|
BLAKE2b-256 checksum How to use checksums |
71205697e72db9a6788729b8eadcd6fb29ba71fa25f4b1c4a1aa8e7af4e9ed30
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.8.0
|
Release files / django_model_auditor-0.0.4-py3-none-any.whl
| Download URL | django_model_auditor-0.0.4-py3-none-any.whl |
|---|---|
| Size | 4.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
961986843c6b64887428bb74b797705b9a5dda82679fb27d4aaeaead754c36fd
|
|
BLAKE2b-256 checksum How to use checksums |
f5254522971489cc8ed975162965c1bb313d4610abd02ddc92dc969424ed0511
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.8.0
|