django-model-history-log
Register fields updates.
WARNING This project currently relies on Django signals (by default
post_save,pre_delete, andm2m_changed), so if you do some bulk action (ie viaqueryset.update()), any action will not be recorded!
Install
Install package with
pip install django-model-history-log
Configure
Add model_history.apps.ModelHistoryConfig into your INSTALLED_APPS
#!python
INSTALLED_APPS = [
...
"model_history.apps.ModelHistoryConfig",
...
]
and then run
./manage.py migrate
Register a model at startup
You can register a model for logging at startup using History.register helper:
class MyAppConfig(AppConfig):
name = "myapp"
def ready(self):
from model_history.models import History
from django.contrib.auth import get_user_model
History.register(get_user_model(), exclude=["password"])
You can register all models with a snippet like this
class MyAppConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "myapp"
verbose_name = _("My Website")
def ready(self):
from django.contrib.admin.models import LogEntry
from django.contrib.auth import get_user_model
from django.contrib.sessions.models import Session
from model_history.models import History, HistoryLog
User = get_user_model()
History.register(User, exclude=["password"])
for model in apps.get_models():
if model not in [LogEntry, History, HistoryLog, Session, User]:
History.register(model)
Usage
Log a single instance
You can log a single instance changes with the HistoryManager.log() method:
instance = MyInstance.objects.get(...)
...
History.objects.log(instance)
Params
instance:models.Model= instance to logexclude:list[str] | None= exclude these fields from loggingserializer_class:rest_framework.serializers.Serializer | None= use this serializer instance
Query a log
from django.contrib.auth import get_user_model
history = History.objects.fetch(User.objects.first())
history.logs.all()
fetch() always returns an History instance, regardless it is saved on db or not.
You must rely on it's pk value or you should check for logs.
CHANGES
0.2.1
- Docs update
0.2.0
- Rename project to django-model-history-log (sorry, no migration path)
- Reformat all codebase with black
- Update isort/flake8 config
- Use django JSONField
- Remove default ordering, use only in admin
- Add register/unregister actions
- Add HistoryQuerySet.fetch api
- Save str(source) as {History,HistoryLog}.label
- Add en translations
- Add it translations
0.1.1
- added missing
on_deleteon HistoryRow.history field
0.1.0
- initial relase
Metadata
Release files for django-model-history-log 0.2.1
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-history-log-0.2.1.tar.gz | 9.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_model_history_log-0.2.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 29.1 kB
Release files / django-model-history-log-0.2.1.tar.gz
| Download URL | django-model-history-log-0.2.1.tar.gz |
|---|---|
| Size | 9.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7674750dd0e9f881d05dec9205638088c723f2b2ab465fe4924542e52404e579
|
|
BLAKE2b-256 checksum How to use checksums |
776afdeb4f2ca13f6e73a411ea984e440cacadca1ab69f7e58f946eed244bc1c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.5
|
Release files / django_model_history_log-0.2.1-py3-none-any.whl
| Download URL | django_model_history_log-0.2.1-py3-none-any.whl |
|---|---|
| Size | 19.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
31ae16ecd99d01ad3f7ec4a048b9d130c58456b7b52a5ee9263c2c3ab793ba8d
|
|
BLAKE2b-256 checksum How to use checksums |
bc36eed7aa37254ef7f6541946121620cc186a9ccfff2cd72ea73eec3c73e54a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.5
|