mirror of
https://github.com/pretix/pretix.git
synced 2026-05-03 14:54:04 +00:00
Added a model for logging actions
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import uuid
|
||||
|
||||
from django.contrib.contenttypes.fields import GenericRelation
|
||||
from django.db import models
|
||||
from django.db.models.signals import post_delete
|
||||
from django.dispatch import receiver
|
||||
@@ -26,3 +27,21 @@ def cached_file_delete(sender, instance, **kwargs):
|
||||
if instance.file:
|
||||
# Pass false so FileField doesn't save the model.
|
||||
instance.file.delete(False)
|
||||
|
||||
|
||||
class LoggedModel(models.Model):
|
||||
logentries = GenericRelation('LogEntry')
|
||||
|
||||
def log_action(self, user, action, data):
|
||||
from .log import LogEntry
|
||||
from .event import Event
|
||||
|
||||
event = None
|
||||
if isinstance(self, Event):
|
||||
event = self
|
||||
elif hasattr(self, 'event'):
|
||||
event = self.event
|
||||
LogEntry.objects.create(content_object=self, user=user, action=action, data=data, event=event)
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
Reference in New Issue
Block a user