Skip to content
Permalink
Browse files

Mutliple Blog Authors (Snippets + Orderable)

  • Loading branch information
KalobTaulien committed Feb 12, 2019
1 parent 58390f3 commit 18c4346541d78e73342e7bcdcbe85852c3257d9e
Showing with 69 additions and 2 deletions.
  1. +28 −0 blog/migrations/0003_blogauthorsorderable.py
  2. +24 −2 blog/models.py
  3. +17 −0 mysite/templates/blog/blog_detail_page.html
@@ -0,0 +1,28 @@
# Generated by Django 2.1.5 on 2019-02-12 16:20

from django.db import migrations, models
import django.db.models.deletion
import modelcluster.fields


class Migration(migrations.Migration):

dependencies = [
('blog', '0002_blogauthor'),
]

operations = [
migrations.CreateModel(
name='BlogAuthorsOrderable',
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)),
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='blog.BlogAuthor')),
('page', modelcluster.fields.ParentalKey(on_delete=django.db.models.deletion.CASCADE, related_name='blog_authors', to='blog.BlogDetailPage')),
],
options={
'ordering': ['sort_order'],
'abstract': False,
},
),
]
@@ -2,21 +2,37 @@
from django.db import models
from django.shortcuts import render

from modelcluster.fields import ParentalKey
from wagtail.admin.edit_handlers import (
FieldPanel,
StreamFieldPanel,
MultiFieldPanel,
InlinePanel,
)
from wagtail.snippets.edit_handlers import SnippetChooserPanel
from wagtail.core.fields import StreamField
from wagtail.core.models import Page
from wagtail.core.models import Page, Orderable
from wagtail.images.edit_handlers import ImageChooserPanel
from wagtail.contrib.routable_page.models import RoutablePageMixin, route
from wagtail.snippets.models import register_snippet


from streams import blocks


class BlogAuthorsOrderable(Orderable):
"""This allows us to select one or more blog authors from Snippets."""

page = ParentalKey("blog.BlogDetailPage", related_name="blog_authors")
author = models.ForeignKey(
"blog.BlogAuthor",
on_delete=models.CASCADE,
)

panels = [
SnippetChooserPanel("author"),
]


class BlogAuthor(models.Model):
"""Blog author for snippets."""

@@ -132,5 +148,11 @@ class BlogDetailPage(Page):
content_panels = Page.content_panels + [
FieldPanel("custom_title"),
ImageChooserPanel("blog_image"),
MultiFieldPanel(
[
InlinePanel("blog_authors", label="Author", min_num=1, max_num=4)
],
heading="Author(s)"
),
StreamFieldPanel("content"),
]
@@ -9,6 +9,23 @@
<div class="container mt-5 mb-5">
<div class="text-center">
<h1>{{ self.custom_title }}</h1>
<div class="d-flex justify-content-center">
{% for iter in self.blog_authors.all %}
{% image iter.author.image fill-50x50 as img %}
<div>
<div>
<img src="{{ img.url }}" class="rounded-circle" alt="{{ iter.author.name }}">
</div>
{% if iter.author.website %}
<a href="{{ iter.author.website }}">
{{ iter.author.name }}
</a>
{% else %}
{{ iter.author.name }}
{% endif %}
</div>
{% endfor %}
</div>
</div>
</div>

1 comment on commit 18c4346

@KalobTaulien

This comment has been minimized.

Copy link
Member Author

KalobTaulien commented on 18c4346 Feb 17, 2019

Please sign in to comment.
You can’t perform that action at this time.