Commit 0d067192 authored by Okhin's avatar Okhin

Ajout d'un article-by-status pour l'API, permettant de filtrer (et donc de...

Ajout d'un article-by-status pour l'API, permettant de filtrer (et donc de compter) les articles dans un status particulier
parent 838c9d53
Pipeline #2675 passed with stages
in 3 minutes and 45 seconds
from rest_framework import routers
from .views import ArticleViewSet, ArticleSearch, ArticleTag
from .views import ArticleViewSet, ArticleSearch, ArticleTag, ArticleStatus
router = routers.DefaultRouter()
router.register(r"articles", ArticleViewSet)
router.register(r"articles-by-status/(?P<filter_status>.+)", ArticleStatus)
router.register(r"articles-by-tag/(?P<filter_tag>.+)", ArticleTag)
router.register(r"articles-search/(?P<search_keywords>.+)", ArticleSearch)
......
......@@ -127,3 +127,12 @@ class ArticleTag(viewsets.ModelViewSet, mixins.ListModelMixin):
def list(self, request, *args, **kwargs):
self.queryset = self.queryset.filter(tags__name__in=[kwargs['filter_tag']]).distinct()
return super().list(request, args, kwargs)
class ArticleStatus(viewsets.ModelViewSet, mixins.ListModelMixin):
queryset = Article.objects.all()
serializer_class = ArticleSerializer
def list(self, request, *args, **kwargs):
self.queryset = self.queryset.filter(status=kwargs['filter_status'].upper())
return super().list(request, args, kwargs)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment