{"id":22295929,"url":"https://github.com/mkalioby/modeltracker","last_synced_at":"2025-07-29T01:32:21.202Z","repository":{"id":57420882,"uuid":"59748406","full_name":"mkalioby/ModelTracker","owner":"mkalioby","description":"Track a model object over time and blame users ","archived":false,"fork":false,"pushed_at":"2024-07-30T08:16:34.000Z","size":112,"stargazers_count":6,"open_issues_count":2,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-07-20T10:06:34.673Z","etag":null,"topics":["django","django-models","django-models-track","middleware"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mkalioby.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-05-26T12:27:54.000Z","updated_at":"2023-07-22T03:36:01.000Z","dependencies_parsed_at":"2024-08-13T07:09:37.826Z","dependency_job_id":"4074a747-02d8-4540-a4f6-5e2ae93c91be","html_url":"https://github.com/mkalioby/ModelTracker","commit_stats":{"total_commits":56,"total_committers":2,"mean_commits":28.0,"dds":0.2857142857142857,"last_synced_commit":"33c304c3fa0892dfb9df186a908f33bd7912e811"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/mkalioby/ModelTracker","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkalioby%2FModelTracker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkalioby%2FModelTracker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkalioby%2FModelTracker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkalioby%2FModelTracker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mkalioby","download_url":"https://codeload.github.com/mkalioby/ModelTracker/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkalioby%2FModelTracker/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267616577,"owners_count":24116154,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-28T02:00:09.689Z","response_time":68,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["django","django-models","django-models-track","middleware"],"created_at":"2024-12-03T17:43:36.282Z","updated_at":"2025-07-29T01:32:20.935Z","avatar_url":"https://github.com/mkalioby.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# django-model-tracker\n\nTrack model object changes over time so that you know who done what.\n\n[![PyPI version](https://badge.fury.io/py/django-model-tracker.svg)](https://badge.fury.io/py/django-model-tracker)\n[![Downloads](https://pepy.tech/badge/django-model-tracker)](https://pepy.tech/project/django-model-tracker)\n \n## Installation\n\n* Install the package\n    * For Django\u003c4.0\n       ```sh\n        pip install 'django-model-tracker jsonfield'\n      ```\n    * For Django\u003e=4.0\n      ```sh\n       pip install 'django-model-tracker'\n      ```\n\n* Add Application to your project's INSTALLED_APPs\n```python\nINSTALLED_APPS = (\n     '....',\n    'ModelTracker',\n    )\n```    \n* Add the following line to your urls.py\n```python\nimport ModelTracker\nurlpatterns = patterns('',\n...\nurl(r'^track/', include('ModelTracker.urls')),\n...\n)\n```\n* Run Migrations\n```sh\n   python manage.py migrate ModelTracker \n```\n\n* Add the following line to your models.py file\n```python\nfrom ModelTracker import Tracker\n```\n*  Convert each Model you want to track to inhert from `Tracker.ModelTracker` instead of `models.Model`\n   \n**Old Code**\n\n```python\n   class Employee(models.Model):\n     name=models.CharField(max_length=255)\n     address=models.CharField(max_length=255)\n     age=models.IntegerField()\n ``` \n  **New Code**\n \n   ```python\n    class Employee(Tracker.ModelTracker):\n      name=models.CharField(max_length=255)\n      address=models.CharField(max_length=255)\n      age=models.IntegerField()\n```\n* For each save() call, add the user the username\n    * Old Code\n ```python\n    emp=Employee()\n    emp.save()\n ``` \n \n     * New Code\n ```python\n        emp=Employee()\n        emp.save(request.user.username)\n ```\n* Starting from version of 0.5, you can pass a event_name parameter to mark change as an event\n \n     * New Code\n ```python\n        emp=Employee()\n        emp.save(request.user.username,event_name=\"Created the user\")\n ```\n\n# Using The Middleware\n\nYou can add `ModelTracker.middleware.ModelTrackerMiddleware` to your Middleware classes to get the username automatically from the request.\n\n```python\nMIDDLEWARE_CLASSES = (\n     '....',\n    'ModelTracker.middleware.ModelTrackerMiddleware',\n    )\n```   \n\n**Note:** If you pass username as `None` then the change won't be saved.\n\n# Showing Record History\n\nThere are 3 ways to see the history of a record\n 1. go to `ModelTracker` url and select `Table` and enter `id`.\n 2. call `showModelChanges` by POST and send `csrftokenmiddleware` to return history as html.\n 3. call `getModelChanges` which returns history as Json.\n\n# Django Admin\n\nThere is 2 ways to update an object by django admin\n1. Handle save and delete in ModelAdmin as follows\n   ```python\n   def save_model(self, request, obj, form, change):\n        obj.save(request.user.username,\"Editing From admin interface\")\n\n   def delete_model(self, request, obj):\n        obj.delete(username=request.user.username, event_name=\"Deleting From admin interface\")\n   ```\n2. Inhert from TrackerAdmin rather ModelAdmin\n   ```python\n   from ModelTracker.Tracker import TrackerAdmin \n   admin.site.register(employee, TrackerAdmin)\n``` \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmkalioby%2Fmodeltracker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmkalioby%2Fmodeltracker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmkalioby%2Fmodeltracker/lists"}