backend/passfinder/events/api/views.py

37 lines
1.1 KiB
Python

from django_filters import DateFilter
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework.generics import GenericAPIView, ListAPIView
from rest_framework.response import Response
from passfinder.events.api.serializers import (
PointSerializer,
RouteSerializer,
RegionSerializer,
)
from passfinder.events.models import BasePoint, Region
class BuildRouteApiView(GenericAPIView):
filter_backends = (DjangoFilterBackend,)
filterset_class = DateFilter
serializer_class = RouteSerializer
def get(self, request):
routes = []
for _ in range(10):
routes.append(
{
"name": "bebra",
"description": "bebra bebra bebra",
"points": PointSerializer(many=True).to_representation(
BasePoint.objects.order_by("?")[:10]
),
}
)
return Response(data=routes)
class ListRegionApiView(ListAPIView):
serializer_class = RegionSerializer
queryset = Region.objects.all()