32 lines
1.1 KiB
Python
32 lines
1.1 KiB
Python
from django.shortcuts import get_object_or_404, render
|
|
from django.http import HttpResponseRedirect
|
|
from django.views import generic
|
|
from django.urls import reverse
|
|
from django.utils import timezone
|
|
from rest_framework import status, viewsets
|
|
from .serializers import MigrationSerializer
|
|
from rest_framework.response import Response
|
|
from rest_framework.decorators import action
|
|
|
|
from .models import Migration
|
|
|
|
|
|
class MigrationViewSet(viewsets.ModelViewSet):
|
|
queryset = Migration.objects.all()
|
|
serializer_class = MigrationSerializer
|
|
# permission_classes = (AllowAny,)
|
|
|
|
@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)
|
|
|
|
|
|
class IndexView(generic.ListView):
|
|
template_name = 'api/index.html'
|
|
context_object_name = 'latest_migrations'
|
|
|
|
def get_queryset(self):
|
|
"""Return the last five published questions (not including those set in the future)."""
|
|
return Migration.objects.filter(booked_time__gte=timezone.now()).order_by('-booked_time')[:5]
|