You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.5 KiB
55 lines
1.5 KiB
from django.db import models
|
|
|
|
from modelcluster.fields import ParentalKey
|
|
|
|
from wagtail.core.models import Page, Orderable
|
|
from wagtail.core.fields import RichTextField
|
|
from wagtail.admin.edit_handlers import FieldPanel, InlinePanel
|
|
from wagtail.images.edit_handlers import ImageChooserPanel
|
|
from wagtail.search import index
|
|
|
|
|
|
class BlogIndexPage(Page):
|
|
intro = RichTextField(blank=True)
|
|
|
|
content_panels = Page.content_panels + [
|
|
FieldPanel('intro', classname="full")
|
|
]
|
|
|
|
|
|
class BlogPage(Page):
|
|
date = models.DateField("Post date")
|
|
intro = models.CharField(max_length=250)
|
|
body = RichTextField(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'),
|
|
]
|
|
|
|
content_panels = Page.content_panels + [
|
|
FieldPanel('date'),
|
|
FieldPanel('intro'),
|
|
FieldPanel('body', classname="full"),
|
|
InlinePanel('gallery_images', label="Obrázky"),
|
|
]
|
|
|
|
|
|
class BlogPageGalleryImage(Orderable):
|
|
page = ParentalKey(BlogPage, 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'),
|
|
]
|
|
|