
11 changed files with 189 additions and 4 deletions
@ -0,0 +1,3 @@ |
|||
from django.contrib import admin |
|||
|
|||
# Register your models here. |
@ -0,0 +1,5 @@ |
|||
from django.apps import AppConfig |
|||
|
|||
|
|||
class TipConfig(AppConfig): |
|||
name = 'tip' |
@ -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'), |
|||
] |
@ -0,0 +1,38 @@ |
|||
{% extends "base.html" %} |
|||
|
|||
{% load wagtailcore_tags wagtailimages_tags static %} |
|||
|
|||
{% block body_class %}template-blogindexpage{% endblock %} |
|||
|
|||
{% block content %} |
|||
|
|||
<h1>{{ page.title }}</h1> |
|||
|
|||
<div class="intro">{{ page.intro|richtext }}</div> |
|||
|
|||
{% for post in page.get_children %} |
|||
{% with post=post.specific %} |
|||
<div class="card mb-3"> |
|||
<div class="row no-gutters"> |
|||
<div class="col-md-4"> |
|||
{% with post.main_image as main_image %} |
|||
{% if main_image %} |
|||
{% image main_image class="card-img" fill-400x150 %} |
|||
{% else %} |
|||
<img src="{% static "img/blank-image.jpg" %}" class="card-img" style="height: 150px;" alt="blank image"> |
|||
{% endif %} |
|||
{% endwith %} |
|||
</div> |
|||
<div class="col-md-8"> |
|||
<div class="card-body"> |
|||
<h5 class="card-title"><a href="{% pageurl post %}">{{ post.title }}</a></h5> |
|||
<p class="card-text">{{ post.intro }}</p> |
|||
<p class="card-text"><small class="text-muted">{{ post.date }}</small></p> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
{% endwith %} |
|||
{% endfor %} |
|||
|
|||
{% endblock %} |
@ -0,0 +1,35 @@ |
|||
{% extends "base.html" %} |
|||
|
|||
{% load wagtailcore_tags wagtailimages_tags %} |
|||
|
|||
{% block body_class %}template-blogpage{% endblock %} |
|||
|
|||
{% block content %} |
|||
<h1>{{ page.title }}</h1> |
|||
<div class="card mb-3"> |
|||
<div class="row no-gutters"> |
|||
<div class="col-md-4"> |
|||
{% for item in page.gallery_images.all %} |
|||
<div style="float: left; margin: 10px"> |
|||
{% image item.image fill-320x240 %} |
|||
<p>{{ item.caption }}</p> |
|||
</div> |
|||
{% endfor %} |
|||
</div> |
|||
<div class="col-md-8"> |
|||
<div class="card-body"> |
|||
|
|||
|
|||
<div class="intro">{{ page.intro }}</div> |
|||
|
|||
{{ page.body|richtext }} |
|||
<p class="meta">{{ page.date }}</p> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
|
|||
|
|||
<p><a href="{{ page.get_parent.url }}">Return to blog</a></p> |
|||
|
|||
{% endblock %} |
@ -0,0 +1,3 @@ |
|||
from django.test import TestCase |
|||
|
|||
# Create your tests here. |
@ -0,0 +1,3 @@ |
|||
from django.shortcuts import render |
|||
|
|||
# Create your views here. |
Loading…
Reference in new issue