Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/blog/api/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from django.urls import path
from .views import AllPostsView, PostDetailView
from .views import AllPostsView, PostDetailView, RulesPostsView

urlpatterns = [
path('', AllPostsView.as_view(), name='blog'),
path('rules', RulesPostsView.as_view(), name='rules'),
path('<slug:slug>/', PostDetailView.as_view(), name='post_detail'),
]
8 changes: 8 additions & 0 deletions src/blog/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,11 @@ def get(self, request, slug):
post = self.get_object()
serializer = self.serializer_class(post)
return Response(serializer.data)

class RulesPostsView(GenericAPIView):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

class LatestRulePostView(GenericAPIView):
    serializer_class = PostSerializer

    def get(self, request):
        post = Post.objects.filter(type='rule', state='published').order_by('-date_created').first()
        if post:
            serializer = self.serializer_class(post)
            return Response(serializer.data)
        else:
            return Response({'detail': 'No published rule post found.'}, status=status.HTTP_404_NOT_FOUND)

try if this works

serializer_class = PostSerializer
queryset = Post.objects.filter(type='rule', state='published').order_by('-date_created').first()
def get(self, request, slug):
post = self.get_object()
serializer = self.serializer_class(post)
return Response(serializer.data)
3 changes: 2 additions & 1 deletion src/blog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ class Post(models.Model):
max_length=12,
choices=(
('no-type', 'No category'),
('weekly', 'Weekly update'),
('weekly', 'Progress update'),
('announcement', 'Announcement'),
('community', 'Community Highlight'),
('rules', 'Rules Update'),
),
default='no-type',
help_text='Select the type of this post',
Expand Down