Added some test views for filtering data
This commit is contained in:
parent
7b15bb75b1
commit
b2b1d15bc2
@ -1,5 +1,6 @@
|
||||
import datetime
|
||||
from django.shortcuts import get_object_or_404, render
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.http import HttpResponseRedirect, JsonResponse
|
||||
from django.views import generic
|
||||
from django.urls import reverse
|
||||
from django.utils import timezone
|
||||
@ -18,14 +19,21 @@ class MigrationViewSet(viewsets.ModelViewSet):
|
||||
|
||||
@action(detail=False, methods=['GET'])
|
||||
def upcoming(self, request, *args, **kwargs):
|
||||
response = {"message": "this will be upcoming migrations"}
|
||||
return Response(response, status=status.HTTP_200_OK)
|
||||
queryset = MigrationSerializer(
|
||||
Migration.objects.filter(booked_time=timezone.now(), migration_status="Booked"), many=True)
|
||||
return Response(queryset.data, status=status.HTTP_200_OK)
|
||||
|
||||
@action(detail=False, methods=['GET'])
|
||||
def missed(self, request, *args, **kwargs):
|
||||
response = {"message": str(Migration.objects.filter(
|
||||
booked_time__gte=timezone.now()).order_by('-booked_time')[:5])}
|
||||
return Response(response, status=status.HTTP_200_OK)
|
||||
queryset = MigrationSerializer(
|
||||
Migration.objects.filter(booked_time__gte=timezone.now() + datetime.timedelta(1), migration_status="Booked"), many=True)
|
||||
return Response(queryset.data, status=status.HTTP_200_OK)
|
||||
|
||||
@action(detail=False, methods=['GET'])
|
||||
def booked(self, request, *args, **kwargs):
|
||||
queryset = MigrationSerializer(Migration.objects.filter(
|
||||
migration_status="booked",), many=True)
|
||||
return Response(queryset.data, status=status.HTTP_200_OK)
|
||||
|
||||
|
||||
class IndexView(generic.ListView):
|
||||
|
||||
Reference in New Issue
Block a user