我需要为用户通过django应用程序中的视图对数据库所做的更改创建一个日志条目。
我已经启用了django管理模块,我可以检索使用管理界面所做更改的日志,如下所示:
from django.contrib.admin.models import LogEntry
from django.contrib.contenttypes.models import ContentType
recentActions = LogEntry.objects.all()
for each in recentActions:
print 'Action:', each.action_flag.__str__()
print 'Message:', each.object_repr
print 'Table:', ContentType.objects.get(id = each.content_type_id).name
我想为其他用户使用django应用程序中的视图所做的操作创建类似的日志条目。我该怎么做?
你离得很近。您只需要创建新的
LogEntry
对象并保存它们。LogEntry
在objects
上有一个快捷函数来执行此操作。相关问题 更多 >
编程相关推荐