from django.db.models import Value from rest_framework.generics import RetrieveAPIView from rest_framework.permissions import IsAuthenticated from drf_yasg.utils import swagger_auto_schema from drf_yasg import openapi from apps.quiz.models import Quiz from apps.quiz.serializers.quiz import QuizSerializer from apps.quiz.doc import * class QuizDetailAPIView(RetrieveAPIView): serializer_class = QuizSerializer permission_classes = [IsAuthenticated] @swagger_auto_schema( operation_description=doc_quiz_detail(), tags=["Imam-Javad - Quiz"], ) def get(self, request, *args, **kwargs): return super().get(request, *args, **kwargs) def get_object(self): return Quiz.objects.filter( id=self.kwargs['quiz_id'], ).annotate( lesson__has_quiz=Value(True) ).select_related('lesson').first()