From fe5189eb2aab8b39ffc1c1b3047a54a7f11806e0 Mon Sep 17 00:00:00 2001 From: MaxIsJoe <34368774+MaxIsJoe@users.noreply.github.com> Date: Thu, 4 Jul 2024 20:20:04 +0300 Subject: [PATCH 1/3] Hub Rules API --- src/blog/api/urls.py | 3 ++- src/blog/api/views.py | 5 +++++ src/blog/models.py | 3 ++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/blog/api/urls.py b/src/blog/api/urls.py index 3cb184b..7a069f4 100644 --- a/src/blog/api/urls.py +++ b/src/blog/api/urls.py @@ -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('/', PostDetailView.as_view(), name='post_detail'), ] \ No newline at end of file diff --git a/src/blog/api/views.py b/src/blog/api/views.py index 88e1b98..389521e 100644 --- a/src/blog/api/views.py +++ b/src/blog/api/views.py @@ -25,3 +25,8 @@ def get(self, request, slug): post = self.get_object() serializer = self.serializer_class(post) return Response(serializer.data) + +class RulesPostsView(ListAPIView): + serializer_class = PostSerializer + queryset = Post.objects.filter(type="rules").order_by('-date_created') + pagination_class = PostsPagination \ No newline at end of file diff --git a/src/blog/models.py b/src/blog/models.py index 960de8f..2bf3222 100644 --- a/src/blog/models.py +++ b/src/blog/models.py @@ -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', From 42ee77c80588752c619152a5f2c42cc99f126f5e Mon Sep 17 00:00:00 2001 From: MaxIsJoe <34368774+MaxIsJoe@users.noreply.github.com> Date: Thu, 4 Jul 2024 20:20:27 +0300 Subject: [PATCH 2/3] Update views.py --- src/blog/api/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/blog/api/views.py b/src/blog/api/views.py index 389521e..dc3924d 100644 --- a/src/blog/api/views.py +++ b/src/blog/api/views.py @@ -28,5 +28,5 @@ def get(self, request, slug): class RulesPostsView(ListAPIView): serializer_class = PostSerializer - queryset = Post.objects.filter(type="rules").order_by('-date_created') + latest_rule_post = Post.objects.filter(type='rule', state='published').order_by('-date_created').first() pagination_class = PostsPagination \ No newline at end of file From b8227fd930022f22a63ee67fc4321b10ee103e3d Mon Sep 17 00:00:00 2001 From: MaxIsJoe <34368774+MaxIsJoe@users.noreply.github.com> Date: Thu, 4 Jul 2024 20:22:36 +0300 Subject: [PATCH 3/3] Update views.py --- src/blog/api/views.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/blog/api/views.py b/src/blog/api/views.py index dc3924d..0e4b85e 100644 --- a/src/blog/api/views.py +++ b/src/blog/api/views.py @@ -26,7 +26,10 @@ def get(self, request, slug): serializer = self.serializer_class(post) return Response(serializer.data) -class RulesPostsView(ListAPIView): +class RulesPostsView(GenericAPIView): serializer_class = PostSerializer - latest_rule_post = Post.objects.filter(type='rule', state='published').order_by('-date_created').first() - pagination_class = PostsPagination \ No newline at end of file + 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) \ No newline at end of file