43 lines
1.3 KiB
Python
43 lines
1.3 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
|
|
|
|
|
|
def get_system_user_id():
|
|
return get_system_user().id
|
|
|
|
|
|
@python_2_unicode_compatible
|
|
class EventChange(models.Model):
|
|
UPDATE = 'update'
|
|
RAISE_FLAG = 'set_flag'
|
|
LOWER_FLAG = 'unset_flag'
|
|
OPERATION_CHOICES = (
|
|
(UPDATE, 'Update'),
|
|
(RAISE_FLAG, 'Raise Flag'),
|
|
(LOWER_FLAG, 'Lower Flag'),
|
|
)
|
|
|
|
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=OPERATION_CHOICES)
|
|
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)
|