diff options
author | Weitian LI <liweitianux@gmail.com> | 2014-04-22 09:26:48 +0800 |
---|---|---|
committer | Weitian LI <liweitianux@gmail.com> | 2014-04-22 09:26:48 +0800 |
commit | b35eca8c38f89af8b30035a973f1edfba416eff6 (patch) | |
tree | b1551b2a2e71b0e0753ae59572e1edfb629c753f /notice | |
parent | 7b9c7d04ba8080910dbf2b733685b3ed27fef6cc (diff) | |
download | django-skaschool-b35eca8c38f89af8b30035a973f1edfba416eff6.tar.bz2 |
* added GenericRelation attachments field to 'Notice' model
* removed 'demo.urls' from urls.py
Diffstat (limited to 'notice')
-rw-r--r-- | notice/admin.py | 4 | ||||
-rw-r--r-- | notice/models.py | 11 |
2 files changed, 8 insertions, 7 deletions
diff --git a/notice/admin.py b/notice/admin.py index f5ec3f8..bed31e4 100644 --- a/notice/admin.py +++ b/notice/admin.py @@ -1,12 +1,12 @@ # -*- coding: utf-8 -*- from django.contrib import admin -from django.contrib.contenttypes.generic import GenericTabularInline +from django.contrib.contenttypes import generic from notice.models import Notice, NoticeCategory, NoticeAttachment -class NoticeAttachmentInline(GenericTabularInline): +class NoticeAttachmentInline(generic.GenericTabularInline): model = NoticeAttachment diff --git a/notice/models.py b/notice/models.py index 469ad07..af2e648 100644 --- a/notice/models.py +++ b/notice/models.py @@ -3,7 +3,7 @@ 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.contrib.contenttypes import generic from django.utils.translation import ugettext_lazy as _ @@ -17,7 +17,8 @@ class Notice(models.Model): publisher = models.ForeignKey(User, verbose_name=_("Publisher")) is_important = models.BooleanField(_("Is important"), default=False) contents = models.TextField(_("Contents")) - # NoticeAttachments to deal with attachments + # NoticeAttachment to deal with attachments + attachments = generic.GenericRelation('NoticeAttachment') class Meta: verbose_name = _('notice') @@ -46,8 +47,8 @@ class NoticeCategory(models.Model): 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") + content_type = models.ForeignKey(ContentType) + object_id = models.PositiveIntegerField() + content_object = generic.GenericForeignKey("content_type", "object_id") |