Skip to main content

An extension to the Django web framework that provides version control for model instances.

Project description

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

  1. Add audits in INSTALLED_APPS inside settings.py of your django project
INSTALLED_APPS = [
    'audits.apps.AuditsConfig',
]
  1. run migration to create auditlog model
python manage.py migrate
  1. 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)
  1. 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

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-model-auditor-0.0.4.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_model_auditor-0.0.4-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file django-model-auditor-0.0.4.tar.gz.

File metadata

  • Download URL: django-model-auditor-0.0.4.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for django-model-auditor-0.0.4.tar.gz
Algorithm Hash digest
SHA256 0b0c31b6d92949c0c25fd3459f7e3dd44bf33f76842054b443179c45cf0d1215
MD5 8975b0a7174c1fda4cbe17d4e738e468
BLAKE2b-256 71205697e72db9a6788729b8eadcd6fb29ba71fa25f4b1c4a1aa8e7af4e9ed30

See more details on using hashes here.

File details

Details for the file django_model_auditor-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: django_model_auditor-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for django_model_auditor-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 961986843c6b64887428bb74b797705b9a5dda82679fb27d4aaeaead754c36fd
MD5 326d23fad1b01b23c502943196e74840
BLAKE2b-256 f5254522971489cc8ed975162965c1bb313d4610abd02ddc92dc969424ed0511

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page