Create blog pages
This commit is contained in:
parent
9769d067bb
commit
7b5d597d34
7 changed files with 126 additions and 0 deletions
0
website/blog/__init__.py
Normal file
0
website/blog/__init__.py
Normal file
77
website/blog/migrations/0001_initial.py
Normal file
77
website/blog/migrations/0001_initial.py
Normal 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),
|
||||||
|
),
|
||||||
|
]
|
0
website/blog/migrations/__init__.py
Normal file
0
website/blog/migrations/__init__.py
Normal file
24
website/blog/models.py
Normal file
24
website/blog/models.py
Normal 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
|
13
website/blog/templates/blog/blog_list_page.html
Normal file
13
website/blog/templates/blog/blog_list_page.html
Normal 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 %}
|
11
website/blog/templates/blog/blog_post_page.html
Normal file
11
website/blog/templates/blog/blog_post_page.html
Normal 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 %}
|
|
@ -22,6 +22,7 @@ INSTALLED_APPS = [
|
||||||
"website.common",
|
"website.common",
|
||||||
"website.home",
|
"website.home",
|
||||||
"website.search",
|
"website.search",
|
||||||
|
"website.blog",
|
||||||
"wagtail.contrib.forms",
|
"wagtail.contrib.forms",
|
||||||
"wagtail.contrib.redirects",
|
"wagtail.contrib.redirects",
|
||||||
"wagtail.embeds",
|
"wagtail.embeds",
|
||||||
|
|
Loading…
Reference in a new issue