diff --git a/tip/__init__.py b/tip/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tip/admin.py b/tip/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/tip/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/tip/apps.py b/tip/apps.py new file mode 100644 index 0000000..98f4ba5 --- /dev/null +++ b/tip/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class TipConfig(AppConfig): + name = 'tip' diff --git a/tip/models.py b/tip/models.py new file mode 100644 index 0000000..bfd75a3 --- /dev/null +++ b/tip/models.py @@ -0,0 +1,92 @@ +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 TipIndexPage(Page): + intro = RichTextField(blank=True) + + content_panels = Page.content_panels + [ + FieldPanel('intro', classname="full") + ] + + +class TipPage(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 TipPageGalleryImage(Orderable): + page = ParentalKey(TipPage, 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'), + ] + +class TipPage(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 TipPageGalleryImage(Orderable): + page = ParentalKey(TipPage, 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'), + ] diff --git a/tip/templates/tip/tip_index_page.html b/tip/templates/tip/tip_index_page.html new file mode 100644 index 0000000..3009422 --- /dev/null +++ b/tip/templates/tip/tip_index_page.html @@ -0,0 +1,38 @@ +{% extends "base.html" %} + +{% load wagtailcore_tags wagtailimages_tags static %} + +{% block body_class %}template-blogindexpage{% endblock %} + +{% block content %} + +
{{ item.caption }}
+