这个django应用程序以一种简单和细粒度的方式记录对模型对象的更改。

django-auditor的Python项目详细描述


这个django应用程序在一个简单的 颗粒状的。此应用程序支持多租户环境 使用django租户模式。

要求

python 3.4

Django 1.8

安装(适用于没有django租户架构的环境)

将“auditor”添加到已安装的应用程序设置中,如下所示:

INSTALLED_APPS=(...'django_auditor',)

在您的设置中添加一个空的dict“auditor”:

AUDITOR={}

在项目url.py中包含auditor urlconf,如下所示:

url(r'^auditor/',include('django_auditor.urls'))

运行python manage.py makemigrations创建迁移 审计员模型的文件。

运行python manage.py migrate以应用迁移和 创建审计员模型。

安装(django租户模式环境)

将“auditor”添加到您的共享应用程序或租户应用程序设置中 像这样:

SHARED_APPS=(...'django_auditor',)

TENANT_APPS=(...'django_auditor',)

在设置中添加dict“auditor”,指定“tenant” 键入租户模型的值:

AUDITOR={'tenant':'customers.Client'}

在项目url.py中包含auditor urlconf,如下所示:

url(r'^auditor/',include('django_auditor.urls'))

运行python manage.py makemigrations创建迁移 审计员模型的文件。

运行python manage.py migrate_schemas以应用迁移和 创建审计员模型。

用法和示例

创建审核传递请求的实例和所需的对象 要记录,请调用方法create()、update()或delete() 使用适当的操作生成日志:创建、更新或 删除。

首先必须导入审核类:

fromdjango_auditor.auditorimportAudit

新对象

new_car=Car(name='Civic',manufacturer='Honda',color='Red')new_car.save()auditor=Audit(request,new_car).create()

Example Create

更新对象

change_car=Car.objects.get(name='Civic')auditor=Audit(request,change_car)change_car.name='City'change_car.color='Yellow'change_car.save()auditor.update()

Example Update

删除对象

remove_car=Car.objects.get(name='City')auditor=Audit(request,remove_car)remove_car.delete()auditor.delete()

Example Delete

现在打开http://yoursiteURL/auditor检查日志。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
如何在Java中使用ENUM生成随机数   Spring4REST应用程序使用Java配置(无xml)IllegalArgumentException   java在Jar中加载新的FXML   java无法将字符串转换为long(时间戳)或long转换为字符串   流我如何通过Java中的grpc(如broadcase)将持续响应从服务器发送到客户端?   java类型不匹配:无法从一个连接转换到另一个连接   带有组织名称、用户名和密码的java Spring引导登录页面   java从Android设备向Windows CE设备发送/获取字符串数据?   java Selenium代码在localhost上运行良好,但无法捕获Jenkins上的StaleElementReferenceException   jodatime如何获取与下一个小时、分钟对应的日期时间?   java在一个int数组中,如何返回对应于最低值的索引?   在web3j中,如何为运行时发现的数组类型创建TypeReference?   java如何仅在Spring Security上对特定URL强制使用https?   java如何添加全局动作事件侦听器?