views.py 645 Bytes
Newer Older
1 2
from rest_framework import viewsets
from rest_framework.response import Response
Aymeric Barantal's avatar
Aymeric Barantal committed
3

4
from picampaign.organization.models import FeedbackCategory, Organization
5 6 7 8 9 10 11 12
from picampaign.organization.serializers import CategorySerializer


class CategoryViewSet(viewsets.ViewSet):

    queryset = FeedbackCategory.objects.all()
    serializer_class = CategorySerializer

13 14 15
    def list(self, request, campaign_pk):
        orga = Organization.objects.filter(campaigns__id=campaign_pk)[0]
        categories = self.queryset.filter(organization_id=orga.id)
16 17
        serializer = self.serializer_class(categories, many=True)
        return Response(serializer.data)