From c7585db6d5174607bb0d8790f6c9a6f6b00580f4 Mon Sep 17 00:00:00 2001 From: Oleg Lavrovsky Date: Tue, 30 May 2017 15:24:00 +0200 Subject: [PATCH] Language specific news --- publichealth/home/models/models.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/publichealth/home/models/models.py b/publichealth/home/models/models.py index 6d73179..b0b2e65 100644 --- a/publichealth/home/models/models.py +++ b/publichealth/home/models/models.py @@ -3,6 +3,8 @@ from __future__ import unicode_literals from django.db import models +from django.utils import translation + from modelcluster.fields import ParentalKey from wagtail.wagtailcore.blocks import StructBlock, CharBlock, URLBlock, RichTextBlock @@ -13,7 +15,7 @@ from wagtail.wagtailimages.blocks import ImageChooserBlock from wagtail.wagtailimages.edit_handlers import ImageChooserPanel from wagtail.wagtailsearch import index -from puput.models import EntryPage +from puput.models import EntryPage, BlogPage from ..util import TranslatedField @@ -182,6 +184,11 @@ class HomePage(Page): 'infos_fr', ) + # news_home_de = models.ForeignKey( + # 'puput.EntryPage', + # null=True, blank=True, on_delete=models.SET_NULL, + # ) + content_panels = Page.content_panels + [ MultiFieldPanel([ FieldPanel('intro_de', classname="full"), @@ -207,8 +214,10 @@ class HomePage(Page): @property def newsfeed(self): # Get list of latest news - # TODO: fetch children of 'News (DE)' - entries = EntryPage.objects.live().descendant_of(self) + curlang = translation.get_language() + parent = BlogPage.objects.filter(slug='news-%s' % curlang) + if not parent: return [] + entries = EntryPage.objects.live().descendant_of(parent[0]) # Order by most recent date first entries = entries.order_by('-date') return entries[:4]