123456789101112131415161718192021222324 |
- # Create your views here.
- import json
- from rest_framework import status
- from rest_framework.response import Response
- from rest_framework.viewsets import ModelViewSet
- from django.forms.models import model_to_dict
- from routes.models import Route, Route2User
- from routes.serializers import RoutesSerializer
- class RoutesView(ModelViewSet):
- queryset = Route.objects.all()
- serializer_class = RoutesSerializer
- pagination_class = None
- # 根据用户id
- def list(self, request, *args, **kwargs):
- now_user_id = request.user.id
- route_ids = Route2User.objects.filter(user_id=now_user_id).values('route_id')
- routes = Route.objects.filter(id__in=route_ids).values()
- return Response(data=routes, status=status.HTTP_200_OK)
|