PostgreSQL的Django模型字段,用于按时间顺序存储对模型的更改。
django-model-audit-histor的Python项目详细描述
#django model audit history
提供一个“audithistory”模型字段,用于按时间顺序存储模型更改的记录(“audit history”)。历史记录存储在指定的json字段中,因此不需要额外的数据库表。
[构建状态](https://travis-ci.org/nexto/django-model-audit-history.svg?branch=master)“(https://travis ci.org/nexto/django model audit history)
\要使此成为模型,您必须进行这些更改:
< BR/> *添加一个名为“历史”的“模型”BR/> *将“AudithistRyMyIXIN”添加到模型类
*创建ModuleAdmin:
` BR/> ModelAdmin(AudithistRyadMadMixin,Admin .Moduladmin):
PASS
``BR/> *添加您的Moduladmin管理站点“admin.site.register(model,modeladmin)”`
2.然后,在更改模型后,不要在模型上调用常规的“save()”,而是调用“save_with_audit_record()”(传入一些要与之一起保存的元数据,例如导致更改的“事件”、“触发更改的“用户”和一些“负载”,通常是一组修改过的字段)。
3。历史记录将以人类可读的形式出现在管理员中。
这几乎就是它的全部内容。
\testapp设置和第一步
1。在本地安装Postgres(例如10.x)
2。创建本地数据库“audithistory”,由用户“dev”拥有
3。创建一个virtualenv并激活:`virtualenv venv`,然后'source venv/bin/activate`
4。将依赖项安装到virtualenv中:`pip install--requirement requirements.txt`
5。运行“manage.py migrate”
6。运行“manage.py createsuperuser”
7。运行“manage.py runserver”
8。在http://localhost:8000/admin/test_app/blogpost/
9上创建新模型。通过http://localhost:8000/edit/1/
10编辑模型。重新加载管理页并检查历史记录
提供一个“audithistory”模型字段,用于按时间顺序存储模型更改的记录(“audit history”)。历史记录存储在指定的json字段中,因此不需要额外的数据库表。
[构建状态](https://travis-ci.org/nexto/django-model-audit-history.svg?branch=master)“(https://travis ci.org/nexto/django model audit history)
\要使此成为模型,您必须进行这些更改:
< BR/> *添加一个名为“历史”的“模型”BR/> *将“AudithistRyMyIXIN”添加到模型类
*创建ModuleAdmin:
` BR/> ModelAdmin(AudithistRyadMadMixin,Admin .Moduladmin):
PASS
``BR/> *添加您的Moduladmin管理站点“admin.site.register(model,modeladmin)”`
2.然后,在更改模型后,不要在模型上调用常规的“save()”,而是调用“save_with_audit_record()”(传入一些要与之一起保存的元数据,例如导致更改的“事件”、“触发更改的“用户”和一些“负载”,通常是一组修改过的字段)。
3。历史记录将以人类可读的形式出现在管理员中。
这几乎就是它的全部内容。
\testapp设置和第一步
1。在本地安装Postgres(例如10.x)
2。创建本地数据库“audithistory”,由用户“dev”拥有
3。创建一个virtualenv并激活:`virtualenv venv`,然后'source venv/bin/activate`
4。将依赖项安装到virtualenv中:`pip install--requirement requirements.txt`
5。运行“manage.py migrate”
6。运行“manage.py createsuperuser”
7。运行“manage.py runserver”
8。在http://localhost:8000/admin/test_app/blogpost/
9上创建新模型。通过http://localhost:8000/edit/1/
10编辑模型。重新加载管理页并检查历史记录