diff --git a/news/managers.py b/news/managers.py index f4ee7415..c25424f5 100644 --- a/news/managers.py +++ b/news/managers.py @@ -1,9 +1,11 @@ from django.db.models import QuerySet +from django.utils import timezone class NewsItemQuerySet(QuerySet): def public(self): return self.filter( - public=True + public=True, + published_at__lt=timezone.now() ) diff --git a/news/templates/news_detail.html b/news/templates/news_detail.html index 7ccde145..26f147a1 100644 --- a/news/templates/news_detail.html +++ b/news/templates/news_detail.html @@ -3,6 +3,11 @@ {% block content %}
+ {% if draft %} +
+ This news item is not yet public. It will become public at {{ news_item.published_at|date:'Y-m-d H:i' }}. +
+ {% endif %}

{{ news_item.title }} {{ news_item.published_at|date:"Y-m-d" }}

{{ news_item.content|commonmark }} diff --git a/news/views.py b/news/views.py index aba60599..3e2af89a 100644 --- a/news/views.py +++ b/news/views.py @@ -1,4 +1,5 @@ from django.views.generic import ListView, DetailView +from django.utils import timezone from . import models @@ -14,3 +15,11 @@ class NewsDetail(DetailView): template_name = 'news_detail.html' context_object_name = 'news_item' + def get_context_data(self, **kwargs): + context = super(NewsDetail, self).get_context_data(**kwargs) + news_item = self.get_object() + context['draft'] = False + if news_item.public and news_item.published_at > timezone.now(): + context['draft'] = True + return context +