Sistema_Gestion_Transporte/project/api/views/linea.py

17 lines
588 B
Python
Executable File

from rest_framework import viewsets
from rest_framework.response import Response
from rest_framework.decorators import action
from .. import models, serializers
class LineaViewSet(viewsets.ModelViewSet):
queryset = models.Linea.objects.all()
serializer_class = serializers.LineaSerializer
@action(detail=False, methods=['GET'])
def servicios(self, request):
distinct_values = models.Linea.objects \
.values('id_linea', 'service_id') \
.order_by('id_linea', 'service_id') \
.distinct()
return Response(distinct_values)