From 3961e2bdfa2cb946f1bd367c9a7a392528bbaeef Mon Sep 17 00:00:00 2001 From: Weitian LI Date: Tue, 24 Jun 2014 17:11:44 +0800 Subject: Splited storage function from account.extra * Splited storage function from account.extra -> tools/storage.py - OverwriteStorage - file_cleanup * Updated account.models, archive.models * Added OverwriteStorage and file_cleanup function to notice.models --- notice/models.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'notice') 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) + + -- cgit v1.2.2