2023-09-07 11:00:44 -03:00
|
|
|
from rest_framework import viewsets, filters
|
2023-08-07 20:31:09 -04:00
|
|
|
from rest_framework.decorators import action, schema, api_view
|
|
|
|
|
from rest_framework.parsers import MultiPartParser
|
2023-09-07 11:00:44 -03:00
|
|
|
from rest_framework.generics import ListAPIView
|
2023-08-07 20:31:09 -04:00
|
|
|
from django.http import JsonResponse, HttpResponse
|
2023-09-07 11:00:44 -03:00
|
|
|
from django_filters.rest_framework import DjangoFilterBackend
|
2023-08-07 20:31:09 -04:00
|
|
|
|
|
|
|
|
from .. import models, serializers
|
|
|
|
|
from ..schemas import ParaderoImageSchema
|
|
|
|
|
from PIL import Image
|
|
|
|
|
import io
|
|
|
|
|
import coreapi
|
|
|
|
|
import logging
|
|
|
|
|
|
|
|
|
|
class ParaderoViewSet(viewsets.ModelViewSet):
|
|
|
|
|
queryset = models.Paradero.objects.all()
|
|
|
|
|
serializer_class = serializers.ParaderoSerializer
|
|
|
|
|
|
2023-09-07 11:00:44 -03:00
|
|
|
# class ParaderoImagenListView(ListAPIView):
|
|
|
|
|
# queryset = models.ParaderoImagen.objects.all()
|
|
|
|
|
# serializer_class = serializers.ParaderoImagenSerializer
|
|
|
|
|
# filter_backends = [filters.SearchFilter]
|
|
|
|
|
# search_fields = ['id_paradero']
|
2023-08-07 20:31:09 -04:00
|
|
|
|
2023-09-07 11:00:44 -03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
def retrieve(self, request, pk):
|
|
|
|
|
data = models.ParaderoImagen.objects.filter(id_paradero_imagen = pk).first()
|
|
|
|
|
response = HttpResponse(content_type=data.content_type)
|
|
|
|
|
response['Content-Disposition'] = 'inline'
|
|
|
|
|
response.write(data.imagen)
|
2023-08-07 20:31:09 -04:00
|
|
|
return response
|
|
|
|
|
|
2023-09-07 11:00:44 -03:00
|
|
|
def create(self, request, pk = None):
|
2023-08-07 20:31:09 -04:00
|
|
|
imagen = request.FILES['imagen']
|
2023-09-07 11:00:44 -03:00
|
|
|
id_paradero = request.data.get('id_paradero')
|
2023-08-07 20:31:09 -04:00
|
|
|
content_type = imagen.content_type
|
|
|
|
|
imagen_bytea = imagen.read()
|
2023-09-07 11:00:44 -03:00
|
|
|
|
|
|
|
|
paradero = models.Paradero.objects.filter(id_paradero = id_paradero).first()
|
|
|
|
|
|
|
|
|
|
paradero_imagen = models.ParaderoImagen(
|
|
|
|
|
id_paradero = paradero,
|
|
|
|
|
imagen = imagen_bytea,
|
|
|
|
|
content_type = content_type
|
|
|
|
|
)
|
|
|
|
|
paradero_imagen.save()
|
|
|
|
|
return JsonResponse({ 'ok': True })
|
|
|
|
|
"""
|