text: from rest_framework import generics
  from ..models import Subject, Course
  from .serializers import SubjectSerializer, CourseSerializer
  from django.shortcuts import get_object_or_404
  from rest_framework.views import APIView
  from rest_framework.response import Response
  from rest_framework.authentication import BasicAuthentication
  from rest_framework.authentication import BasicAuthentication
  from rest_framework.permissions import IsAuthenticated
  from rest_framework import viewsets
  
  
  
  class SubjectListView(generics.ListAPIView):
  	queryset = Subject.objects.all()
  	serializer_class = SubjectSerializer
  
  class SubjectDetailView(generics.RetrieveAPIView):
  	queryset = Subject.objects.all()
  	serializer_class = SubjectSerializer
  
  class CourseEnrollView(APIView):
  	authentication_classes = (BasicAuthentication,)
  	permission_classes = (IsAuthenticated,)
  
  	def post(self, request, pk, format=None):
  		course = get_object_or_404(Course, pk=pk)
  		course.students.add(request.user)
  		return Response({'enrolled': True})
  
  class CourseViewSet(viewsets.ReadOnlyModelViewSet):
  	queryset = Course.objects.all()
  	serializer_class = CourseSerializer
  