38 lines
1.2 KiB
Python
38 lines
1.2 KiB
Python
# -*- coding: utf-8 -*-
|
|
from __future__ import unicode_literals
|
|
from django.conf import settings
|
|
from django.db import models
|
|
from django.utils import timezone
|
|
from django.utils.encoding import python_2_unicode_compatible
|
|
|
|
from . import get_ghost_user, get_system_user
|
|
|
|
CHANGE_OPERATIONS = (
|
|
('update', 'update'),
|
|
)
|
|
|
|
|
|
def get_system_user_id():
|
|
return get_system_user().id
|
|
|
|
|
|
@python_2_unicode_compatible
|
|
class EventChange(models.Model):
|
|
event = models.ForeignKey('dav_events.Event', related_name='changes')
|
|
timestamp = models.DateTimeField(default=timezone.now)
|
|
user = models.ForeignKey(settings.AUTH_USER_MODEL,
|
|
default=get_system_user_id,
|
|
on_delete=models.SET(get_ghost_user),
|
|
related_name='+')
|
|
|
|
operation = models.CharField(max_length=20, choices=CHANGE_OPERATIONS)
|
|
content = models.TextField()
|
|
|
|
class Meta:
|
|
ordering = ['event', 'timestamp']
|
|
|
|
def __str__(self):
|
|
s = '{timestamp} - {user} - {operation}'
|
|
return s.format(operation=self.operation, timestamp=self.timestamp.strftime('%d.%m.%Y %H:%M:%S %Z'),
|
|
user=self.user)
|