diff options
author | Weitian LI <liweitianux@gmail.com> | 2014-04-21 23:31:08 +0800 |
---|---|---|
committer | Weitian LI <liweitianux@gmail.com> | 2014-04-21 23:31:08 +0800 |
commit | 39f939d39ee6fc796baf2ce7848ed5e920f5d128 (patch) | |
tree | 90b03385d650f1730f844d5865d8bc1472054edf /notice | |
parent | a8e2d41bd7e9e647391ff5d675f66cd59eee851a (diff) | |
download | django-skaschool-39f939d39ee6fc796baf2ce7848ed5e920f5d128.tar.bz2 |
* added 'MEDIA_ROOT' to settings.py
* implemented 'Notice', 'NoticeCategory', 'NoticeAttachment' models
* implemented 'NoticeAdmin' with 'NoticeAttachmentInline'
Diffstat (limited to 'notice')
-rw-r--r-- | notice/admin.py | 21 | ||||
-rw-r--r-- | notice/models.py | 52 |
2 files changed, 71 insertions, 2 deletions
diff --git a/notice/admin.py b/notice/admin.py index 8c38f3f..f5ec3f8 100644 --- a/notice/admin.py +++ b/notice/admin.py @@ -1,3 +1,22 @@ +# -*- coding: utf-8 -*- + from django.contrib import admin +from django.contrib.contenttypes.generic import GenericTabularInline + +from notice.models import Notice, NoticeCategory, NoticeAttachment + + +class NoticeAttachmentInline(GenericTabularInline): + model = NoticeAttachment + + +class NoticeAdmin(admin.ModelAdmin): + inlines = [ + NoticeAttachmentInline, + ] + + +## register to admin +admin.site.register(Notice, NoticeAdmin) +admin.site.register(NoticeCategory) -# Register your models here. diff --git a/notice/models.py b/notice/models.py index 71a8362..469ad07 100644 --- a/notice/models.py +++ b/notice/models.py @@ -1,3 +1,53 @@ +# -*- coding: utf-8 -*- + from django.db import models +from django.contrib.auth.models import User +from django.contrib.contenttypes.models import ContentType +from django.contrib.contenttypes.generic import GenericForeignKey +from django.utils.translation import ugettext_lazy as _ + + +class Notice(models.Model): + """ + model 'Notice' to record and display notice + """ + title = models.CharField(_("Title"), max_length=100) + pubtime = models.DateTimeField(_("Publish time"), auto_now_add=True) + category = models.ForeignKey('NoticeCategory', verbose_name=_("Category")) + publisher = models.ForeignKey(User, verbose_name=_("Publisher")) + is_important = models.BooleanField(_("Is important"), default=False) + contents = models.TextField(_("Contents")) + # NoticeAttachments to deal with attachments + + class Meta: + verbose_name = _('notice') + verbose_name_plural = _('notices') + ordering = ['-pubtime', 'id'] + + def __unicode__(self): + return u'Notice at %s' % self.pubtime.isoformat() + + +class NoticeCategory(models.Model): + """ + model 'NoticeCategory' to provide category selections for 'Notice' + """ + category_name = models.CharField(_("Category name"), max_length=100) + created_time = models.DateTimeField(_("Created time"), auto_now_add=True) + + class Meta: + verbose_name = _('notice category') + verbose_name_plural = _('notice categories') + + def __unicode__(self): + return u'NoticeCategory : %s' % self.category_name + + +class NoticeAttachment(models.Model): + attachment = models.FileField(upload_to='notice/attachments', + verbose_name=_("Attachment")) + content_type = models.ForeignKey(ContentType, verbose_name=_("Content type")) + object_id = models.PositiveIntegerField(_("Object ID")) + content_object = GenericForeignKey("content_type", "object_id") + -# Create your models here. |