Skip to main content
=====
Django Model History
=====

The package is designed to track changes in object models. It has the ability to roll back changes to the object and attempt to restore an object if it has been deleted.
If the change of the object were conducted script or from the console, the user field will be empty.

=====
Quick start
=====
0. Install::

pip install django-model-history2

1. Add in INSTALLED_APPS::

INSTALLED_APPS = (
...
'model_history'
)

3. Make migrate::

python manage.py migrate model_history

4. Add decorator model_hisotry to your Model class:

.. code-block:: python

from model_history.decorators import model_history

@model_history()
class SomeModel(models.Model):
field_one = models.CharField()
last_modified = models.DateTimeField()


=====
Arguments for decorator model_history
=====
1. ``exclude`` - Exclude fields. Default: []::

@model_hisotry(exclude=['last_modified'])

2. ``related`` - Track all related models. Default: False::

@model_history(exclude=['last_modified'], related=True)

3. ``related_exclude`` - Exclude for related models. Default: []::

@model_history(exclude=['last_modified'], related=True, related_exclude=['myapp.models.Model2'])

=====
Settings
=====
1. The settings are defined in the dictionary named ``MODEL_HISTORY_SETTINGS``::

MODEL_HISTORY_SETTINGS = {
'connect': [
{'model': 'django.contrib.auth.models.User', 'exclude': ['last_login'], 'related': True, 'related_exclude': ['django.contrib.admin.models.LogEntry']}
]
}
2. Models are listed in parameter ``connect`` will be put on track, with the specified parameters.
3. ``delete_action`` - Should be in the admin interface function "delete selected objects". Default: False::

MODEL_HISTORY_SETTINGS = {
'delete_action': True
'connect': [
{'model': 'django.contrib.auth.models.User', 'exclude': ['last_login'], 'related': True, 'related_exclude': ['django.contrib.admin.models.LogEntry']}
]
}
4. ``delete_permission`` - Which option is the user to check for compliance with the availability of the right to delete entries from the history::

MODEL_HISTORY_SETTINGS = {
'delete_action': True,
'delete_permission': 'is_superuser',
'connect': [
{'model': 'django.contrib.auth.models.User', 'exclude': ['last_login'], 'related': True, 'related_exclude': ['django.contrib.admin.models.LogEntry']}
]
}
5. ``revert_action`` - Should be in the admin function "Revert". This function tries to make changes or cancellation recover a deleted object from the dump. Default: True::

MODEL_HISTORY_SETTINGS = {
'delete_action': True,
'delete_permission': 'is_superuser',
'revert_action': True,
'connect': [
{'model': 'django.contrib.auth.models.User', 'exclude': ['last_login'], 'related': True, 'related_exclude': ['django.contrib.admin.models.LogEntry']}
]
}
6. ``revert_permission`` - Which option is the user to check for compliance with the availability of rights to recovery facility::

MODEL_HISTORY_SETTINGS = {
'delete_action': True,
'delete_permission': 'is_superuser',
'revert_action': True,
'revert_permission': 'is_superuser',
'connect': [
{'model': 'django.contrib.auth.models.User', 'exclude': ['last_login'], 'related': True, 'related_exclude': ['django.contrib.admin.models.LogEntry']}
]
}

=====
Changelist
=====
* 0.9.3:

* Add ``track_created`` in ``MODEL_HISTORY_SETTINGS`` for tracking new object created. Default: False.
* Add ``dispatch_uid`` for connected signals.
* Model ``History`` small refactoring.

* 0.9.2:

* Refactor settings import

Release files for django-model-history2 0.9.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-model-history2 0.9.3
File Size Uploaded
django-model-history2-0.9.3.zip 13.6 kB Details

Release files / django-model-history2-0.9.3.zip

Download URL django-model-history2-0.9.3.zip
Size 13.6 kB
Tags Source
SHA-256 checksum
How to use checksums
d9bff95995e7be4e2a345790686a39c21fd9fa2dcfa7defa98d89a04be506487
BLAKE2b-256 checksum
How to use checksums
4d3f29430ab63ccefb7cf3083a3e48e9c18364852e6187f07e4cbc9108e5b6b5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.9.3 This release

1 release file

0.9.2

0.9.1

1 release file

0.9.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page