Skip to content

Commit

Permalink
fix unpublished articles on public news page
Browse files Browse the repository at this point in the history
  • Loading branch information
sirodoht committed May 25, 2024
1 parent 0dfda79 commit 4db5998
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions main/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.contrib.messages.views import SuccessMessageMixin
from django.shortcuts import render
from django.urls import reverse_lazy
from django.utils import timezone
from django.views.generic import DetailView, ListView
from django.views.generic.edit import FormView

Expand All @@ -19,8 +20,11 @@ class NewsList(ListView):
def get_queryset(self):
if self.request.user.is_authenticated:
return models.Article.objects.all().order_by("-published_at")
return models.Article.objects.filter(published_at__isnull=False).order_by(
"-published_at"
today = timezone.now().date()
return (
models.Article.objects.filter(published_at__isnull=False)
.filter(published_at__lte=today)
.order_by("-published_at")
)


Expand Down

0 comments on commit 4db5998

Please sign in to comment.