Added a model for logging actions

This commit is contained in:
Raphael Michel
2015-12-12 15:41:48 +01:00
parent 493b80a481
commit 83b5fa2fa6
9 changed files with 98 additions and 10 deletions

View File

@@ -0,0 +1,30 @@
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.db import models
class LogEntry(models.Model):
"""
Represents a change or action that has been performed on another object
in the database. This uses django.contrib.contenttypes to allow a
relation to an arbitrary database object.
:param user: The user that performed the action
:type user: User
:param action_type: The type of action that has been performed. This is
used to look up the renderer used to describe the action in a human-
readable way. This should be some namespaced value using dotted
notationto avaoid duplicates, e.g.
``"pretix.plugins.banktransfer.incoming_transfer"``.
:type action_type: str
:param data: Arbitrary data that can be used by the log action renderer
:type data: str
"""
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
object_id = models.PositiveIntegerField()
content_object = GenericForeignKey('content_type', 'object_id')
datetime = models.DateTimeField(auto_now_add=True)
user = models.ForeignKey('User', null=True, blank=True, on_delete=models.PROTECT)
event = models.ForeignKey('Event', null=True, blank=True, on_delete=models.CASCADE)
action_type = models.CharField(max_length=255)
data = models.TextField(default='{}')