From e5bb97a04b32218eeee3d5c2ca0f6f727c78dc20 Mon Sep 17 00:00:00 2001 From: baoliang Date: Sun, 13 Sep 2020 14:06:58 +0800 Subject: [PATCH] add cms model --- NewMediaMonitoring/settings.py | 2 +- polls/models.py | 68 +++++++++++++++++++++++++++++++++- 2 files changed, 67 insertions(+), 3 deletions(-) diff --git a/NewMediaMonitoring/settings.py b/NewMediaMonitoring/settings.py index b029f97..c736fe7 100644 --- a/NewMediaMonitoring/settings.py +++ b/NewMediaMonitoring/settings.py @@ -104,7 +104,7 @@ ASGI_APPLICATION = 'NewMediaMonitoring.routing.application' DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', - 'NAME': 'nmm', + 'NAME': 'newmediaDB1', 'USER': 'newmedia', 'PASSWORD': 'newmedia2020!@#', 'HOST': '210.77.68.250', diff --git a/polls/models.py b/polls/models.py index dfe8aeb..b71a8b5 100644 --- a/polls/models.py +++ b/polls/models.py @@ -2,6 +2,16 @@ from django.db import models import uuid import datetime from django.contrib.auth.models import User +from django.db import models +from modelcluster.fields import ParentalKey, ParentalManyToManyField + +from wagtail.core.models import Page, Orderable +from wagtail.core.models import Page +from wagtail.core.fields import RichTextField +from wagtail.admin.edit_handlers import FieldPanel, InlinePanel, MultiFieldPanel +from wagtail.images.edit_handlers import ImageChooserPanel +from wagtail.snippets.models import register_snippet + from dashboard.models import Group @@ -84,17 +94,71 @@ class URLMessage(Message): class FileMessage(Message): title = models.CharField('title', max_length=256, null=False) - file = models.FileField(upload_to='message/file/%Y/%m/%d/', null=True, blank=True) + file = models.FileField( + upload_to='message/file/%Y/%m/%d/', null=True, blank=True) + class ImageMessage(Message): - file = models.FileField(upload_to='resources/image/%Y/%m/%d/', null=True, blank=True) + file = models.FileField( + upload_to='resources/image/%Y/%m/%d/', null=True, blank=True) class MessageRecord(models.Model): pass + class ChatRecord(models.Model): pass +class NewsPage(Page): + date = models.DateField("Post date") + source = models.CharField(max_length=64) + intro = models.CharField(max_length=250) + body = RichTextField(blank=True) + categories = ParentalManyToManyField('polls.NewsCategory', blank=True) + def main_image(self): + gallery_item = self.gallery_images.first() + if gallery_item: + return gallery_item.image + else: + return None + + content_panels = Page.content_panels + [ + FieldPanel('date'), + FieldPanel('source'), + FieldPanel('categories'), + FieldPanel('intro'), + FieldPanel('body', classname="full"), + InlinePanel('gallery_images', label="Gallery images"), + ] + + +class NewsPageGalleryImage(Orderable): + page = ParentalKey(NewsPage, on_delete=models.CASCADE, + related_name='gallery_images') + image = models.ForeignKey( + 'wagtailimages.Image', on_delete=models.CASCADE, related_name='+' + ) + caption = models.CharField(blank=True, max_length=250) + + panels = [ + ImageChooserPanel('image'), + FieldPanel('caption'), + ] + + +@register_snippet +class NewsCategory(models.Model): + name = models.CharField(max_length=255) + + panels = [ + FieldPanel('name'), + ] + + def __str__(self): + return self.name + + class Meta: + verbose_name_plural = 'news categories'