diff --git a/.gitignore b/.gitignore
index 13d1490..8346735 100644
--- a/.gitignore
+++ b/.gitignore
@@ -129,3 +129,4 @@ dmypy.json
# Pyre type checker
.pyre/
+media/
\ No newline at end of file
diff --git a/blog/static/css/blog.css b/blog/static/css/blog.css
index e69de29..45cd297 100644
--- a/blog/static/css/blog.css
+++ b/blog/static/css/blog.css
@@ -0,0 +1,17 @@
+
+main > .container {
+ padding: 60px 15px 0;
+}
+
+.footer {
+ background-color: #f5f5f5;
+}
+
+.footer > .container {
+ padding-right: 15px;
+ padding-left: 15px;
+}
+
+code {
+ font-size: 80%;
+}
diff --git a/blog/templates/base.html b/blog/templates/base.html
index 97a9752..d53d141 100644
--- a/blog/templates/base.html
+++ b/blog/templates/base.html
@@ -1,7 +1,7 @@
{% load static wagtailuserbar %}
-
+
@@ -15,20 +15,59 @@
{% endblock %}
-
+
{# Global stylesheets #}
+
-
+
{% block extra_css %}
{# Override this in templates to add extra stylesheets #}
{% endblock %}
-
- {% wagtailuserbar %}
+
+
+
+
+
+
+
+ {% block content %}{% endblock %}
+
+
- {% block content %}{% endblock %}
+
{# Global javascript #}
diff --git a/zapisnik/migrations/0003_blogpagegalleryimage.py b/zapisnik/migrations/0003_blogpagegalleryimage.py
new file mode 100644
index 0000000..5a6ffdc
--- /dev/null
+++ b/zapisnik/migrations/0003_blogpagegalleryimage.py
@@ -0,0 +1,30 @@
+# Generated by Django 3.1.2 on 2020-10-23 09:03
+
+from django.db import migrations, models
+import django.db.models.deletion
+import modelcluster.fields
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('wagtailimages', '0022_uploadedimage'),
+ ('zapisnik', '0002_blogpage'),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='BlogPageGalleryImage',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('sort_order', models.IntegerField(blank=True, editable=False, null=True)),
+ ('caption', models.CharField(blank=True, max_length=250)),
+ ('image', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='+', to='wagtailimages.image')),
+ ('page', modelcluster.fields.ParentalKey(on_delete=django.db.models.deletion.CASCADE, related_name='gallery_images', to='zapisnik.blogpage')),
+ ],
+ options={
+ 'ordering': ['sort_order'],
+ 'abstract': False,
+ },
+ ),
+ ]
diff --git a/zapisnik/models.py b/zapisnik/models.py
index 6d27806..2a21b1c 100644
--- a/zapisnik/models.py
+++ b/zapisnik/models.py
@@ -1,10 +1,11 @@
from django.db import models
-# Create your models here.
+from modelcluster.fields import ParentalKey
-from wagtail.core.models import Page
+from wagtail.core.models import Page, Orderable
from wagtail.core.fields import RichTextField
-from wagtail.admin.edit_handlers import FieldPanel
+from wagtail.admin.edit_handlers import FieldPanel, InlinePanel
+from wagtail.images.edit_handlers import ImageChooserPanel
from wagtail.search import index
@@ -21,6 +22,13 @@ class BlogPage(Page):
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'),
@@ -30,4 +38,18 @@ class BlogPage(Page):
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'),
]
diff --git a/zapisnik/templates/zapisnik/blog_index_page.html b/zapisnik/templates/zapisnik/blog_index_page.html
index 0f0b870..ce9aedd 100644
--- a/zapisnik/templates/zapisnik/blog_index_page.html
+++ b/zapisnik/templates/zapisnik/blog_index_page.html
@@ -1,6 +1,6 @@
{% extends "base.html" %}
-{% load wagtailcore_tags %}
+{% load wagtailcore_tags wagtailimages_tags %}
{% block body_class %}template-blogindexpage{% endblock %}
@@ -10,9 +10,16 @@
{{ page.intro|richtext }}
{% for post in page.get_children %}
-
- {{ post.specific.intro }}
- {# {{ post.specific.body|richtext }} #}
+ {% with post=post.specific %}
+
+
+ {% with post.main_image as main_image %}
+ {% if main_image %}{% image main_image fill-160x100 %}{% endif %}
+ {% endwith %}
+
+ {{ post.intro }}
+ {# {{ post.body|richtext }} #}
+ {% endwith %}
{% endfor %}
{% endblock %}
diff --git a/zapisnik/templates/zapisnik/blog_page.html b/zapisnik/templates/zapisnik/blog_page.html
index 150118c..33929c3 100644
--- a/zapisnik/templates/zapisnik/blog_page.html
+++ b/zapisnik/templates/zapisnik/blog_page.html
@@ -1,6 +1,6 @@
{% extends "base.html" %}
-{% load wagtailcore_tags %}
+{% load wagtailcore_tags wagtailimages_tags %}
{% block body_class %}template-blogpage{% endblock %}
@@ -12,6 +12,13 @@
{{ page.body|richtext }}
+ {% for item in page.gallery_images.all %}
+
+ {% image item.image fill-320x240 %}
+
{{ item.caption }}
+
+ {% endfor %}
+
Return to blog
-{% endblock %}
+{% endblock %}
\ No newline at end of file