Skip to content

Commit

Permalink
Make news date editable
Browse files Browse the repository at this point in the history
  • Loading branch information
Merlin Buczek committed Sep 11, 2019
1 parent 84228d8 commit 8c7e187
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
18 changes: 18 additions & 0 deletions mpicms/news/migrations/0018_newsentry_show_in_main_news.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.2.4 on 2019-09-11 09:06

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('news', '0017_auto_20190909_1515'),
]

operations = [
migrations.AddField(
model_name='newsentry',
name='show_in_main_news',
field=models.BooleanField(default=False),
),
]
19 changes: 19 additions & 0 deletions mpicms/news/migrations/0019_auto_20190911_1119.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 2.2.4 on 2019-09-11 09:19

import datetime
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('news', '0018_newsentry_show_in_main_news'),
]

operations = [
migrations.AlterField(
model_name='newsentry',
name='date',
field=models.DateField(default=datetime.date.today, verbose_name='date'),
),
]
18 changes: 15 additions & 3 deletions mpicms/news/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from datetime import date

from django.db import models
from django.utils.translation import gettext_lazy as _
from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
Expand All @@ -6,6 +8,7 @@
from wagtail.search import index
from wagtail.api import APIField
from wagtail.images.edit_handlers import ImageChooserPanel
from wagtail.admin.edit_handlers import FieldPanel

from mpicms.base.models import CategoryMixin
from mpicms.base.mixins import BasePage, BodyMixin
Expand Down Expand Up @@ -43,9 +46,12 @@ def is_news_root(self):

@property
def news_items(self):
items = NewsEntry.objects.child_of(self).live().order_by('-date')
if self.is_news_root:
return NewsEntry.objects.live().order_by('-date')
return NewsEntry.objects.child_of(self).live().order_by('-date')
imported_news = NewsEntry.objects.live().filter(show_in_main_news=True)
combined_items = list(items) + list(imported_news)
items = sorted(combined_items, key=lambda x: x.date, reverse=True)
return items


class Meta: # noqa
Expand All @@ -54,21 +60,27 @@ class Meta: # noqa


class NewsEntry(CategoryMixin, BodyMixin, BasePage):
date = models.DateField(_("post date"), auto_now_add=True)
date = models.DateField(_("date"), default=date.today)
header_image = models.ForeignKey(
'wagtailimages.Image',
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name='+'
)
show_in_main_news = models.BooleanField(default=False)

show_in_menus_default = False

content_panels = Page.content_panels + BodyMixin.content_panels + [
FieldPanel('date'),
ImageChooserPanel('header_image'),
]

promote_panels = Page.promote_panels + [
FieldPanel('show_in_main_news')
]

search_fields = Page.search_fields + BodyMixin.search_fields + [
index.FilterField('date')
]
Expand Down

0 comments on commit 8c7e187

Please sign in to comment.