Tomas Harazim 5 years ago
parent
commit
599ff85eac
  1. BIN
      media/images/20201009_150710_1.2e16d0ba.fill-160x100.jpg
  2. BIN
      media/images/20201009_150710_1.2e16d0ba.fill-320x240.jpg
  3. BIN
      media/images/20201009_150710_1.max-165x165.jpg
  4. BIN
      media/original_images/20201009_150710_1.jpg
  5. 30
      zapisnik/migrations/0003_blogpagegalleryimage.py
  6. 32
      zapisnik/models.py
  7. 18
      zapisnik/templates/zapisnik/blog_index_page.html
  8. 9
      zapisnik/templates/zapisnik/blog_page.html

BIN
media/images/20201009_150710_1.2e16d0ba.fill-160x100.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

BIN
media/images/20201009_150710_1.2e16d0ba.fill-320x240.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
media/images/20201009_150710_1.max-165x165.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

BIN
media/original_images/20201009_150710_1.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 MiB

30
zapisnik/migrations/0003_blogpagegalleryimage.py

@ -0,0 +1,30 @@
# Generated by Django 3.1.2 on 2020-10-23 09:11
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,
},
),
]

32
zapisnik/models.py

@ -2,10 +2,18 @@ from django.db import models
# Create your models here.
from wagtail.core.models import Page
from wagtail.core.fields import RichTextField
from wagtail.admin.edit_handlers import FieldPanel
from wagtail.search import index
from modelcluster.fields import ParentalKey
from wagtail.core.models import Page, Orderable
from wagtail.admin.edit_handlers import FieldPanel, InlinePanel
from wagtail.images.edit_handlers import ImageChooserPanel
g
class BlogIndexPage(Page):
@ -16,9 +24,17 @@ class BlogIndexPage(Page):
]
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'),
@ -29,4 +45,18 @@ class BlogPage(Page):
FieldPanel('date'),
FieldPanel('intro'),
FieldPanel('body', classname="full"),
InlinePanel('gallery_images', label="Gallery images"),
]
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'),
]

18
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 %}
@ -9,10 +9,18 @@
<div class="intro">{{ page.intro|richtext }}</div>
{% for post in page.get_children %}
<h2><a href="{% pageurl post %}">{{ post.title }}</a></h2>
{{ post.specific.intro }}
{# {{ post.specific.body|richtext }} #}
{% with post=post.specific %}
<h2><a href="{% pageurl post %}">{{ post.title }}</a></h2>
{% with post.main_image as main_image %}
{% if main_image %}{% image main_image fill-160x100 %}{% endif %}
{% endwith %}
<p>{{ post.intro }}</p>
{% endwith %}
{% endfor %}
{% endblock %}

9
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 %}
<div style="float: left; margin: 10px">
{% image item.image fill-320x240 %}
<p>{{ item.caption }}</p>
</div>
{% endfor %}
<div style="clear: left;"></div>
<p><a href="{{ page.get_parent.url }}">Return to blog</a></p>
{% endblock %}
Loading…
Cancel
Save