from rest_framework import viewsets
from rest_framework.response import Response

from mneia_admin_backend.models import WorkURL
from mneia_admin_backend.serializers import WorkURLSerializer


class WorkURLViewSet(viewsets.ModelViewSet):
    serializer_class = WorkURLSerializer
    queryset = WorkURL.objects.all()

    def list(self, request):
        queryset = WorkURL.objects.all()
        work_id = request.query_params.get("work")
        if work_id is not None:
            queryset = queryset.filter(work__id=work_id)
        serializer = WorkURLSerializer(queryset, many=True)
        return Response(serializer.data)

from rest_framework import viewsets
from rest_framework.response import Response

from mneia_admin_backend.models import WorkURL
from mneia_admin_backend.serializers import WorkURLSerializer


class WorkURLViewSet(viewsets.ModelViewSet):
    serializer_class = WorkURLSerializer
    queryset = WorkURL.objects.all()

    def list(self, request):
        queryset = WorkURL.objects.all()
        work_id = request.query_params.get("work")
        if work_id is not None:
            queryset = queryset.filter(work__id=work_id)
        serializer = WorkURLSerializer(queryset, many=True)
        return Response(serializer.data)
