diff options
author | Weitian LI <liweitianux@gmail.com> | 2014-06-24 17:11:44 +0800 |
---|---|---|
committer | Weitian LI <liweitianux@gmail.com> | 2014-06-24 17:11:44 +0800 |
commit | 3961e2bdfa2cb946f1bd367c9a7a392528bbaeef (patch) | |
tree | 326b178af4a91ae875a490d10a2904412a8f29a3 /notice | |
parent | ed3d74e61300f91818eeff9dad7e9d35c556f75a (diff) | |
download | django-skaschool-3961e2bdfa2cb946f1bd367c9a7a392528bbaeef.tar.bz2 |
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
Diffstat (limited to 'notice')
-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) + + |