Model Tracker
Track model object changes over time so that you know who done what.
Installation
- Install the package
pip install django-model-tracker
- 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.
Metadata
Release files for DjangoModelTracker 1.3.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| DjangoModelTracker-1.3.9.tar.gz | 59.0 kB | Details |
Release files / DjangoModelTracker-1.3.9.tar.gz
| Download URL | DjangoModelTracker-1.3.9.tar.gz |
|---|---|
| Size | 59.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8a2ed5e19451a70c7ad8315668631be0de71a2ed4154884b00abbae3a8890466
|
|
BLAKE2b-256 checksum How to use checksums |
8d7ae1504964339a0d11352562235f242c8d0b18e6ce2a6dc06cdd3c7bfdf911
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.23.0 CPython/3.5.7
|