Make publication depend on 'published_at' field
This commit is contained in:
parent
4a778497ce
commit
ef00c130f9
|
@ -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()
|
||||
)
|
||||
|
|
|
@ -3,6 +3,11 @@
|
|||
|
||||
{% block content %}
|
||||
<div>
|
||||
{% if draft %}
|
||||
<div class="alert alert-danger">
|
||||
<strong>This news item is not yet public.</strong> It will become public at {{ news_item.published_at|date:'Y-m-d H:i' }}.
|
||||
</div>
|
||||
{% endif %}
|
||||
<h3>{{ news_item.title }} <small>{{ news_item.published_at|date:"Y-m-d" }}</small></h3>
|
||||
</div>
|
||||
{{ news_item.content|commonmark }}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue