django-model-tracker
Track model object changes over time so that you know who done what.
Installation
-
Install the package
- For Django<4.0
pip install 'django-model-tracker jsonfield'
- For Django>=4.0
pip install 'django-model-tracker'
- For Django<4.0
-
Add Application to your project's INSTALLED_APPs
INSTALLED_APPS = (
'....',
'ModelTracker',
)
- Add the following line to your urls.py
import ModelTracker
urlpatterns = patterns('',
...
url(r'^track/', include('ModelTracker.urls')),
...
)
- Run Migrations
python manage.py migrate ModelTracker
- Add the following line to your models.py file
from ModelTracker import Tracker
- Convert each Model you want to track to inhert from
Tracker.ModelTrackerinstead ofmodels.Model
Old Code
class Employee(models.Model):
name=models.CharField(max_length=255)
address=models.CharField(max_length=255)
age=models.IntegerField()
New Code
class Employee(Tracker.ModelTracker):
name=models.CharField(max_length=255)
address=models.CharField(max_length=255)
age=models.IntegerField()
- For each save() call, add the user the username
- Old Code
emp=Employee()
emp.save()
* New Code
emp=Employee()
emp.save(request.user.username)
-
Starting from version of 0.5, you can pass a event_name parameter to mark change as an event
- New Code
emp=Employee()
emp.save(request.user.username,event_name="Created the user")
Using The Middleware
You can add ModelTracker.middleware.ModelTrackerMiddleware to your Middleware classes to get the username automatically from the request.
MIDDLEWARE_CLASSES = (
'....',
'ModelTracker.middleware.ModelTrackerMiddleware',
)
Note: If you pass username as None then the change won't be saved.
Showing Record History
There are 3 ways to see the history of a record
- go to
ModelTrackerurl and selectTableand enterid. - call
showModelChangesby POST and sendcsrftokenmiddlewareto return history as html. - call
getModelChangeswhich returns history as Json.
Django Admin
There is 2 ways to update an object by django admin
- Handle save and delete in ModelAdmin as follows
def save_model(self, request, obj, form, change): obj.save(request.user.username,"Editing From admin interface") def delete_model(self, request, obj): obj.delete(username=request.user.username, event_name="Deleting From admin interface")
- Inhert from TrackerAdmin rather ModelAdmin
from ModelTracker.Tracker import TrackerAdmin admin.site.register(employee, TrackerAdmin)
Metadata
Release files for django-model-tracker 2.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 | Provenance | Actions |
|---|---|---|---|---|
| django-model-tracker-2.0.4.tar.gz | 62.0 kB | Without provenance | Details for django-model-tracker-2.0.4.tar.gz |
Release files / django-model-tracker-2.0.4.tar.gz
| Download URL | django-model-tracker-2.0.4.tar.gz |
|---|---|
| Size | 62.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2da94b112b0ea4dd85b2a8e56bec21fddc28569cc1946e8a35215089ea62eba2
|
|
BLAKE2b-256 checksum How to use checksums |
3d551c3a34615abc5474a65218a6b18884c3a8803dcaab12128c78efac4d7ab6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 colorama/0.4.5 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.28.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.25.10 CPython/3.10.6
|
Security for django-model-tracker 2.0.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.