Create blog pages

This commit is contained in:
Jake Howard 2022-06-19 19:24:29 +01:00
parent 9769d067bb
commit 7b5d597d34
Signed by: jake
GPG key ID: 57AFB45680EDD477
7 changed files with 126 additions and 0 deletions

0
website/blog/__init__.py Normal file
View file

View file

@ -0,0 +1,77 @@
# Generated by Django 4.0.5 on 2022-06-19 18:13
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
("wagtailimages", "0024_index_image_file_hash"),
("wagtailcore", "0069_log_entry_jsonfield"),
]
operations = [
migrations.CreateModel(
name="BlogPostPage",
fields=[
(
"page_ptr",
models.OneToOneField(
auto_created=True,
on_delete=django.db.models.deletion.CASCADE,
parent_link=True,
primary_key=True,
serialize=False,
to="wagtailcore.page",
),
),
("subtitle", models.CharField(blank=True, max_length=255)),
(
"hero_image",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
to="wagtailimages.image",
),
),
],
options={
"abstract": False,
},
bases=("wagtailcore.page", models.Model),
),
migrations.CreateModel(
name="BlogListPage",
fields=[
(
"page_ptr",
models.OneToOneField(
auto_created=True,
on_delete=django.db.models.deletion.CASCADE,
parent_link=True,
primary_key=True,
serialize=False,
to="wagtailcore.page",
),
),
("subtitle", models.CharField(blank=True, max_length=255)),
(
"hero_image",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
to="wagtailimages.image",
),
),
],
options={
"abstract": False,
},
bases=("wagtailcore.page", models.Model),
),
]

View file

24
website/blog/models.py Normal file
View file

@ -0,0 +1,24 @@
from typing import Any
from django.http.request import HttpRequest
from website.common.models import BaseContentMixin, BasePage
class BlogListPage(BaseContentMixin, BasePage): # type: ignore[misc]
max_count = 1
subpage_types = ["blog.BlogPostPage"]
content_panels = BasePage.content_panels + BaseContentMixin.content_panels
def get_context(self, request: HttpRequest) -> dict:
context = super().get_context(request)
context["child_pages"] = (
self.get_children().live().specific().select_related("hero_image")
)
return context
class BlogPostPage(BaseContentMixin, BasePage): # type: ignore[misc]
subpage_types: list[Any] = []
parent_page_types = [BlogListPage]
content_panels = BasePage.content_panels + BaseContentMixin.content_panels

View file

@ -0,0 +1,13 @@
{% extends "wagtail_base.html" %}
{% block content %}
{% include "common/hero.html" %}
<div class="container">
{% for page in child_pages %}
{% include "common/listing-item.html" %}
{% endfor %}
</div>
{% endblock content %}

View file

@ -0,0 +1,11 @@
{% extends "wagtail_base.html" %}
{% block content %}
{% include "common/hero.html" %}
<section class="container content">
{% lorem 10 p %}
</section>
{% endblock content %}

View file

@ -22,6 +22,7 @@ INSTALLED_APPS = [
"website.common",
"website.home",
"website.search",
"website.blog",
"wagtail.contrib.forms",
"wagtail.contrib.redirects",
"wagtail.embeds",