diff options
Diffstat (limited to 'notice/models.py')
-rw-r--r-- | notice/models.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/notice/models.py b/notice/models.py index 92b34e5..3f33e4d 100644 --- a/notice/models.py +++ b/notice/models.py @@ -1,11 +1,14 @@ # -*- coding: utf-8 -*- from django.db import models +from django.db.models.signals import pre_delete from django.contrib.auth.models import User -from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes import generic +from django.contrib.contenttypes.models import ContentType from django.utils.translation import ugettext_lazy as _ +from tools.storage import OverwriteStorage, file_cleanup + class Notice(models.Model): """ @@ -52,7 +55,8 @@ class NoticeAttachment(models.Model): title = models.CharField(_("Title"), max_length=100) description = models.TextField(_("Description"), blank=True) attachment = models.FileField(upload_to='notice/attachments', - verbose_name=_("Attachment")) + verbose_name=_("Attachment"), + storage=OverwriteStorage) content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() content_object = generic.GenericForeignKey("content_type", "object_id") @@ -62,3 +66,7 @@ class NoticeAttachment(models.Model): verbose_name_plural = _('notice attachments') +### connect to signal and sender +pre_delete.connect(file_cleanup, sender=NoticeAttachment) + + |