views.py 709 Bytes
Newer Older
Thibaut Broggi's avatar
Thibaut Broggi committed
1
from rest_framework import viewsets, mixins
luxcem's avatar
luxcem committed
2
3
4
5

from rp.models import Article
from .serializers import ArticleSerializer

6
7
from .mixins import get_viewset_transition_actions_mixin
ArticleMixin = get_viewset_transition_actions_mixin(Article)
luxcem's avatar
luxcem committed
8

9
10

class ArticleViewSet(ArticleMixin, viewsets.ModelViewSet):
luxcem's avatar
luxcem committed
11
12
    queryset = Article.objects.all()
    serializer_class = ArticleSerializer
Thibaut Broggi's avatar
Thibaut Broggi committed
13
14
15
16
17
18
19
20

class ArticleSearch(viewsets.ModelViewSet, mixins.ListModelMixin):
    queryset = Article.objects.all()
    serializer_class = ArticleSerializer

    def list(self, request, *args, **kwargs):
        self.queryset = self.queryset.filter(title__icontains=kwargs['search_keywords'])
        return super().list(request, args, kwargs)