from rest_framework import generics, viewsets
from django_filters.rest_framework import DjangoFilterBackend
from django.http import HttpResponse
from api.models import ParaderoImagen
from api.serializers import ParaderoImagenSerializer

class ParaderoImagenListView(generics.ListAPIView, viewsets.ModelViewSet):
    queryset = ParaderoImagen.objects.all()
    serializer_class = ParaderoImagenSerializer
    filter_backends = [DjangoFilterBackend]
    filterset_fields = ['id_paradero', 'content_type']

    def retrieve(self, request, pk):
        data = ParaderoImagen.objects.filter(id_paradero_imagen = pk).first()
        response = HttpResponse(content_type=data.content_type)
        response['Content-Disposition'] = 'inline'
        response.write(data.imagen)
        return response