{"id":16750877,"url":"https://github.com/ildus/django-history","last_synced_at":"2025-10-14T09:37:24.955Z","repository":{"id":1636133,"uuid":"2360528","full_name":"ildus/django-history","owner":"ildus","description":"Full history for django models","archived":false,"fork":false,"pushed_at":"2015-04-06T18:32:30.000Z","size":132,"stargazers_count":19,"open_issues_count":0,"forks_count":8,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-29T01:58:48.523Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ildus.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-09-10T11:23:01.000Z","updated_at":"2024-01-17T18:15:53.000Z","dependencies_parsed_at":"2022-07-18T18:42:06.222Z","dependency_job_id":null,"html_url":"https://github.com/ildus/django-history","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ildus/django-history","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ildus%2Fdjango-history","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ildus%2Fdjango-history/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ildus%2Fdjango-history/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ildus%2Fdjango-history/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ildus","download_url":"https://codeload.github.com/ildus/django-history/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ildus%2Fdjango-history/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263421933,"owners_count":23464049,"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","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":[],"created_at":"2024-10-13T02:42:31.228Z","updated_at":"2025-10-14T09:37:19.909Z","avatar_url":"https://github.com/ildus.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"Общее описание\n--------------\n\nПриложение для сохранения истории изменений\nобъектов. Технику взял из книги [Pro Django (автор Marty Alchin)][1].\n\nПриложение умеет:\n\n  1. сохранять все изменения объекта \n  2. откатывать изменения \n  3. просто включается, не требует создания вручную моделей для сохранения истории, при этом история изменений хранится в разных таблицах для каждой модели \n\nМожно установить с помощью pip:\n\n    pip install -e git+git://github.com/ildus/django-history.git#egg=django-history\n\nУстановка:\n----------\n\n  * добавляем в мидлвары `django_history.current_context.CurrentUserMiddleware`\n  * в модели, для которого нужно сохранять историю, добавляем   \n  \n    \n    from django_history.models import HistoricalRecords\n    history = HistoricalRecords()\n\n  * выполнить syncdb \n\n  \nMiddleware нужен, для того чтобы сохранить какой пользователь сделал\nизменения.\n\nИспользование:\n--------------\n\nМожно получить историю всех изменений в модели или объекте модели. Например,\nтак\n\n    \u003e\u003e\u003e from main.models import Poll\n    \u003e\u003e\u003e Poll.objects.create(language = 'en',question = 'Where are we?')\n    \u003cPoll: Where are we?\u003e\n    \u003e\u003e\u003e poll = Poll.objects.all()[0]\n    \u003e\u003e\u003e poll.language = 'ru'\n    \u003e\u003e\u003e poll.save()\n    \u003e\u003e\u003e poll.history.all()\n    [\u003cHistoricalPoll: Changed by None on 2011-09-10 15:49:48.609916, {'language': (u'en', 'ru')}\u003e, \u003cHistoricalPoll: Created by None on 2011-09-10 15:49:00.355074, {}\u003e]\n    \nПри авторизованном пользователе, будет видно кто изменил объект.\n\nМожно откатывать изменения. Нужно учесть, что откат тоже является изменением и\nтоже идет в историю\n\n    \u003e\u003e\u003e poll.history.all()[0].revert()\n    \u003e\u003e\u003e poll.history.all()\n    [\u003cHistoricalPoll: Changed by None on 2011-09-10 17:24:30.570957, {'language': (u'ru', u'en')}\u003e, \u003cHistoricalPoll: Created by None on 2011-09-10 15:49:00.355074, {}\u003e]\n    \nМожно получать историю не только по объекту, но и по всей модели\n\n    \u003e\u003e\u003e poll2 = Poll.objects.create(language = 'cz',question = 'Who are we?')\n    \u003e\u003e\u003e poll2.language = 'cs'\n    \u003e\u003e\u003e poll2.save()\n    \u003e\u003e\u003e Poll.history.all()\n    [\u003cHistoricalPoll: Changed by None on 2011-09-10 17:27:01.669054, {'language': (u'cz', 'cs')}\u003e, \u003cHistoricalPoll: Created by None on 2011-09-10 17:26:30.827953, {}\u003e, \u003cHistoricalPoll: Created by None on 2011-09-10 17:25:57.839304, {}\u003e, \u003cHistoricalPoll: Changed by None on 2011-09-10 17:24:30.570957, {'language': (u'ru', u'en')}\u003e, \u003cHistoricalPoll: Created by None on 2011-09-10 15:49:00.355074, {}\u003e]\n    \nВот и все! Детали реализации лучше смотреть прямо в коде, благо его там не так\nмного. А если коротко, то все реализовано через сигналы и метода\ncontribute_to_class, который отрабатывает для полей модели.\n\n   [1]: http://prodjango.com/\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fildus%2Fdjango-history","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fildus%2Fdjango-history","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fildus%2Fdjango-history/lists"}