From b35eca8c38f89af8b30035a973f1edfba416eff6 Mon Sep 17 00:00:00 2001 From: Weitian LI Date: Tue, 22 Apr 2014 09:26:48 +0800 Subject: * added GenericRelation attachments field to 'Notice' model * removed 'demo.urls' from urls.py --- notice/models.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'notice/models.py') 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") -- cgit v1.2.2