Archived
1
Fork 0
This repository has been archived on 2024-10-15. You can view files and clone it, but cannot push or open issues or pull requests.
lps-wagtail/lps/blog/models.py
2024-06-12 18:47:41 +02:00

54 lines
1.5 KiB
Python

from django.db import models
from wagtail.admin.panels import FieldPanel
from wagtail.fields import RichTextField
from wagtail.models import Page
class BlogPage(Page):
introduction = models.TextField(help_text="Introduction de l'article", blank=True)
image = models.ForeignKey(
"wagtailimages.Image",
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name="+",
help_text="Image de l'article",
)
body = RichTextField(blank=True)
date_published = models.DateField("Date de publication de l'article")
content_panels = Page.content_panels + [
FieldPanel("introduction"),
FieldPanel("image"),
FieldPanel("body"),
FieldPanel("date_published"),
]
class BlogIndexPage(Page):
introduction = models.TextField(help_text="Description de la page", blank=True)
image = models.ForeignKey(
"wagtailimages.Image",
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name="+",
help_text="Image du blog",
)
content_panels = Page.content_panels + [
FieldPanel("introduction"),
FieldPanel("image"),
]
subpage_types = ["BlogPage"]
def children(self):
return self.get_children().specific().live()
def get_context(self, request):
context = super().get_context(request)
context["posts"] = (
BlogPage.objects.descendant_of(self).live().order_by("-date_published")
)
return context