Only display published articles

This commit is contained in:
Gabriel Augendre 2020-08-14 16:19:02 +02:00
parent 02d7169314
commit 0c1d0a0b29
2 changed files with 8 additions and 0 deletions

View file

@ -8,5 +8,7 @@
<p>{{ article.get_abstract|safe }}</p>
<p><a href="{% url 'article-detail' pk=article.pk %}">Read more</a></p>
</article>
{% empty %}
<p>No article here. Come back later 🙂</p>
{% endfor %}
{% endblock %}

View file

@ -8,7 +8,13 @@ class ArticlesListView(generic.ListView):
paginate_by = 15
context_object_name = "articles"
def get_queryset(self):
return super().get_queryset().filter(status=Article.PUBLISHED)
class ArticleDetailView(generic.DetailView):
model = Article
context_object_name = "article"
def get_queryset(self):
return super().get_queryset().filter(status=Article.PUBLISHED)