diff --git a/media/images/20201009_150710_1.2e16d0ba.fill-160x100.jpg b/media/images/20201009_150710_1.2e16d0ba.fill-160x100.jpg new file mode 100644 index 0000000..5dc2323 Binary files /dev/null and b/media/images/20201009_150710_1.2e16d0ba.fill-160x100.jpg differ diff --git a/media/images/20201009_150710_1.2e16d0ba.fill-320x240.jpg b/media/images/20201009_150710_1.2e16d0ba.fill-320x240.jpg new file mode 100644 index 0000000..16b35f4 Binary files /dev/null and b/media/images/20201009_150710_1.2e16d0ba.fill-320x240.jpg differ diff --git a/media/images/20201009_150710_1.max-165x165.jpg b/media/images/20201009_150710_1.max-165x165.jpg new file mode 100644 index 0000000..31e1f2e Binary files /dev/null and b/media/images/20201009_150710_1.max-165x165.jpg differ diff --git a/media/original_images/20201009_150710_1.jpg b/media/original_images/20201009_150710_1.jpg new file mode 100644 index 0000000..bb070db Binary files /dev/null and b/media/original_images/20201009_150710_1.jpg differ diff --git a/zapisnik/migrations/0003_blogpagegalleryimage.py b/zapisnik/migrations/0003_blogpagegalleryimage.py new file mode 100644 index 0000000..2e3c8ac --- /dev/null +++ b/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, + }, + ), + ] diff --git a/zapisnik/models.py b/zapisnik/models.py index 333eec6..aa275d5 100644 --- a/zapisnik/models.py +++ b/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'), + ] + diff --git a/zapisnik/templates/zapisnik/blog_index_page.html b/zapisnik/templates/zapisnik/blog_index_page.html index 18a3a65..8aa0a94 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 %} @@ -9,10 +9,18 @@
{{ post.intro }}
+ + {% endwith %} {% endfor %} - {% endblock %} \ No newline at end of file diff --git a/zapisnik/templates/zapisnik/blog_page.html b/zapisnik/templates/zapisnik/blog_page.html index bf7da56..471b3a9 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 %} +{{ item.caption }}
+