Django应用,用于跟踪系统中的所有动作/事件。
项目描述
# Django History Actions
Django应用,用于跟踪系统中的动作/事件。
[](https://travis-ci.org/marcosschroh/django-history-actions)
[](https://codecov.io/gh/marcosschroh/django-history-actions)
[](https://github.com/marcosschroh/django-history-actions/blob/master/LICENSE)

## **目录**
- [功能](#features)
- [模型描述](#model-description)
- [快速入门](#quickstart)
- [系统名称](#system-name)
- [信号](#signals)
- [运行测试](#running-tests)
### 功能
1. 保存您的django模型的历史记录。
2. 定义全局系统名称或按模型定义
3. 动作应用程序检查器。
4. 信号以跟踪已保存的模型。
### 模型描述
| 字段 | 描述 | 类型 | 必填 | 默认 |
|:-------------|:-----------------|:-----|:---------|:--------------------|
| author | 动作作者(用户名) | str | True | |
| action | 执行的动作 | str | True | |
| system | 系统名称 | str | True | 从设置或模型实例中获取 |
| actor | 参与动作的演员(用户名) | str | False | |
| created | 动作创建的日期时间 | Datetime | False | 自动生成 |
| content_type | 模型实例的内容类型 | str | False | 从模型实例自动生成 |
| object_pk | 对象pk | int | False | 从模型实例获取 |
| notes | 与动作相关的额外注释 | TextField | False | |
| 额外 | 额外字段用于存储可序列化对象。 | 文本字段 | False | |
### 快速入门
安装 Django History Actions
```bash
pip install django-history-events
```
将其添加到您的 `INSTALLED_APPS`
```python
INSTALLED_APPS = (
...
'history_actions',
...
)
# 定义您的系统名称
HISTORY_ACTIONS_SYSTEM = 'main'
```
在您的应用程序中定义 actions.py
```python
# actions.py
from django.utils.translation import ugettext_lazy as _
INFO_TRAINING_SAVE_ACTION = 'INFO_TRAINING_SAVE_ACTION'
ACTIONS = {
'INFO_TRAINING_SAVE_ACTION': _('info trainig save action')
}
```
现在您可以跟踪历史记录了
```python
from history_actions.manager import HistoryManager
# 记录一个事件
HistoryManager.create(
'an_author', 'INFO_TRAINING_SAVE_ACTION')
# 记录与模型相关联的事件
model_instance = ModelKlass.objects.first()
HistoryManager.create(
'an_author', 'INFO_TRAINING_SAVE_ACTION', model_instance=model_instance)
# 记录包含更多信息的与模型相关联的事件
username = User.ojects.first().username
HistoryActions.create(
'an_author', 'INFO_TRAINING_SAVE_ACTION', model_instance=model_instance, actor=username, notes='我的笔记')
# 记录与模型相关联并序列化模型的事件
username = User.ojects.first().username
model_instance_dict = model_instance.to_dict()
HistoryActions.create(
'an_author', 'INFO_TRAINING_SAVE_ACTION', model_instance=model_instance, actor=username, notes='我的笔记', extra=model_instace_dict)
# 使用不同的系统
HistoryActions.create(
'an_author', 'INFO_TRAINING_SAVE_ACTION', model_instance=model_instance, actor=username, notes='我的笔记', extra=model_instace_dict, system="custom")
```
如果您想为模型跟踪使用不同的系统,可以在以下位置定义它
```python
# models.py
class Chatdentity(MachuBaseModel)
HISTORY_ACTION_SYSTEM = 'chat'
user = models.OneToOneField(User)
user_two = models.OneToOneField(User, related_name='user_manager')
given_name = models.CharField(
'Given Name(s)', max_length=200, default='')
family_name = models.CharField(
'Family Name(s)', max_length=200, default='')
```
### 系统名称
系统名称来自以下内容
1. `create` 方法的 `kwargs`。
2. 来自 `settings.py` 中定义的 `HISTORY_ACTIONS_SYSTEM` 变量。
3. 在模型类中定义的 `HISTORY_ACTION_SYSTEM` 类变量。
### 信号
### 运行测试
```bash
source <YOURVIRTUALENV>/bin/activate
(myenv) $ pip install tox
(myenv) $ tox
```
Django应用,用于跟踪系统中的动作/事件。
[](https://travis-ci.org/marcosschroh/django-history-actions)
[](https://codecov.io/gh/marcosschroh/django-history-actions)
[](https://github.com/marcosschroh/django-history-actions/blob/master/LICENSE)

## **目录**
- [功能](#features)
- [模型描述](#model-description)
- [快速入门](#quickstart)
- [系统名称](#system-name)
- [信号](#signals)
- [运行测试](#running-tests)
### 功能
1. 保存您的django模型的历史记录。
2. 定义全局系统名称或按模型定义
3. 动作应用程序检查器。
4. 信号以跟踪已保存的模型。
### 模型描述
| 字段 | 描述 | 类型 | 必填 | 默认 |
|:-------------|:-----------------|:-----|:---------|:--------------------|
| author | 动作作者(用户名) | str | True | |
| action | 执行的动作 | str | True | |
| system | 系统名称 | str | True | 从设置或模型实例中获取 |
| actor | 参与动作的演员(用户名) | str | False | |
| created | 动作创建的日期时间 | Datetime | False | 自动生成 |
| content_type | 模型实例的内容类型 | str | False | 从模型实例自动生成 |
| object_pk | 对象pk | int | False | 从模型实例获取 |
| notes | 与动作相关的额外注释 | TextField | False | |
| 额外 | 额外字段用于存储可序列化对象。 | 文本字段 | False | |
### 快速入门
安装 Django History Actions
```bash
pip install django-history-events
```
将其添加到您的 `INSTALLED_APPS`
```python
INSTALLED_APPS = (
...
'history_actions',
...
)
# 定义您的系统名称
HISTORY_ACTIONS_SYSTEM = 'main'
```
在您的应用程序中定义 actions.py
```python
# actions.py
from django.utils.translation import ugettext_lazy as _
INFO_TRAINING_SAVE_ACTION = 'INFO_TRAINING_SAVE_ACTION'
ACTIONS = {
'INFO_TRAINING_SAVE_ACTION': _('info trainig save action')
}
```
现在您可以跟踪历史记录了
```python
from history_actions.manager import HistoryManager
# 记录一个事件
HistoryManager.create(
'an_author', 'INFO_TRAINING_SAVE_ACTION')
# 记录与模型相关联的事件
model_instance = ModelKlass.objects.first()
HistoryManager.create(
'an_author', 'INFO_TRAINING_SAVE_ACTION', model_instance=model_instance)
# 记录包含更多信息的与模型相关联的事件
username = User.ojects.first().username
HistoryActions.create(
'an_author', 'INFO_TRAINING_SAVE_ACTION', model_instance=model_instance, actor=username, notes='我的笔记')
# 记录与模型相关联并序列化模型的事件
username = User.ojects.first().username
model_instance_dict = model_instance.to_dict()
HistoryActions.create(
'an_author', 'INFO_TRAINING_SAVE_ACTION', model_instance=model_instance, actor=username, notes='我的笔记', extra=model_instace_dict)
# 使用不同的系统
HistoryActions.create(
'an_author', 'INFO_TRAINING_SAVE_ACTION', model_instance=model_instance, actor=username, notes='我的笔记', extra=model_instace_dict, system="custom")
```
如果您想为模型跟踪使用不同的系统,可以在以下位置定义它
```python
# models.py
class Chatdentity(MachuBaseModel)
HISTORY_ACTION_SYSTEM = 'chat'
user = models.OneToOneField(User)
user_two = models.OneToOneField(User, related_name='user_manager')
given_name = models.CharField(
'Given Name(s)', max_length=200, default='')
family_name = models.CharField(
'Family Name(s)', max_length=200, default='')
```
### 系统名称
系统名称来自以下内容
1. `create` 方法的 `kwargs`。
2. 来自 `settings.py` 中定义的 `HISTORY_ACTIONS_SYSTEM` 变量。
3. 在模型类中定义的 `HISTORY_ACTION_SYSTEM` 类变量。
### 信号
### 运行测试
```bash
source <YOURVIRTUALENV>/bin/activate
(myenv) $ pip install tox
(myenv) $ tox
```
项目详情
下载文件
下载适用于您的平台的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。
源分布
django-history-actions-0.1.1.tar.gz (8.3 kB 查看哈希值)
构建分布
关闭
散列值 for django_history_actions-0.1.1-py2.py3-none-any.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 0dcd7875268f53b08174a2286fc2cb264c535ea40386f39765d3e11036f22fe4 |
|
MD5 | f8d38ddc0cc6d2c6abbfbc911d2cfb52 |
|
BLAKE2b-256 | 7adf84ea6721429eb3f10b7d7772fc1e07816d0cbf59117b631b3e51923ab413 |