Populate latest blog post on homepage
This commit is contained in:
parent
71c08f5568
commit
e7617f24de
2 changed files with 17 additions and 4 deletions
|
@ -1,7 +1,9 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.http.request import HttpRequest
|
||||||
from wagtail.admin.panels import FieldPanel
|
from wagtail.admin.panels import FieldPanel
|
||||||
from wagtail.images import get_image_model_string
|
from wagtail.images import get_image_model_string
|
||||||
|
|
||||||
|
from website.blog.models import BlogPostPage
|
||||||
from website.common.models import BasePage
|
from website.common.models import BasePage
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,3 +19,12 @@ class HomePage(BasePage):
|
||||||
FieldPanel("heading"),
|
FieldPanel("heading"),
|
||||||
FieldPanel("image"),
|
FieldPanel("image"),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def get_context(self, request: HttpRequest) -> dict:
|
||||||
|
context = super().get_context(request)
|
||||||
|
context["latest_blog_post"] = (
|
||||||
|
BlogPostPage.objects.live() # type:ignore[attr-defined]
|
||||||
|
.defer_streamfields()
|
||||||
|
.latest("date")
|
||||||
|
)
|
||||||
|
return context
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{% extends "wagtail_base.html" %}
|
{% extends "wagtail_base.html" %}
|
||||||
|
|
||||||
{% load wagtailimages_tags %}
|
{% load wagtailcore_tags wagtailimages_tags %}
|
||||||
|
|
||||||
{% block main %}
|
{% block main %}
|
||||||
<main {% if page.image %}style="background-image: url({% image_url page.image 'width-1200' %})"{% endif %}>
|
<main {% if page.image %}style="background-image: url({% image_url page.image 'width-1200' %})"{% endif %}>
|
||||||
|
@ -9,8 +9,10 @@
|
||||||
<input id="search-input" class="input" type="text" placeholder="Search">
|
<input id="search-input" class="input" type="text" placeholder="Search">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="box latest">
|
{% if latest_blog_post %}
|
||||||
<strong>Latest Post</strong>: <a href="#">{% lorem 6 w random %}</a> →
|
<div class="box latest">
|
||||||
</div>
|
<strong>Latest Post</strong>: <a href="{% pageurl latest_blog_post %}">{{ latest_blog_post.title }}</a> →
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
</main>
|
</main>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
Loading…
Reference in a new issue