**This is my page model**
from taggit.models import TaggedItemBase
class ProductionPageTag(TaggedItemBase):
content_object = ParentalKey(
'ProductionPage',
related_name='tagged_items',
on_delete=models.CASCADE
)
class ProductionPage(Page):
date = models.DateField(null=True, verbose_name="Post date")
intro = models.CharField(blank=True, null=True, verbose_name='简介', max_length=250)
body = RichTextField(null=True, verbose_name='内容主体', blank=True)
tags = ClusterTaggableManager(through=ProductionPageTag, blank=True)
def main_image(self):
gallery_item = self.gallery_images.first()
if gallery_item:
return gallery_item.image
else:
return None
search_fields = Page.search_fields + [
index.SearchField('intro'),
index.SearchField('body'),
]
api_fields = [
APIField("body"),
APIField("date"),
APIField("gallery_images"),
]
content_panels = Page.content_panels + [
MultiFieldPanel([
FieldPanel('date'),
FieldPanel('tags'),
], heading="文章信息"),
FieldPanel('intro'),
FieldPanel('body', classname="full"),
InlinePanel('gallery_images', heading='作品图片集 --- 第一张图选为封面', label="图片"),
]
class Meta:
verbose_name = "Production Page"
verbose_name_plural = "Production Pages"