1 # -*- coding: utf-8 -*-
2 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
3 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
5 from django.db import models
6 from django.db.models.signals import pre_delete
8 from catalogue.models import Book, Tag
11 class Deleted(models.Model):
12 object_id = models.IntegerField()
13 type = models.CharField(max_length="50", db_index=True)
14 created_at = models.DateTimeField(editable=False, db_index=True)
15 deleted_at = models.DateTimeField(auto_now_add=True, db_index=True)
18 unique_together = (('type', 'object_id'),)
22 def _pre_delete_handler(sender, instance, **kwargs):
23 """ save deleted objects for change history purposes """
25 if sender in (Book, Tag):
26 Deleted.objects.create(type=sender.__name__, object_id=instance.id, created_at=instance.created_at)
27 pre_delete.connect(_pre_delete_handler)