Commit f4e237d4 authored by okhin's avatar okhin 🚴

Merge branch '60-l-api-ne-permet-pas-de-connaitre-le-nombre-d-articles-en-attente' into 'rp2'

Resolve "L'API ne permet pas de connaitre le nombre d'articles en attente"

Closes #60

See merge request !55
parents e573336e 0d067192
Pipeline #2676 passed with stages
in 4 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