mirror of
https://github.com/lemeow125/StudE-Backend.git
synced 2024-11-17 06:19:24 +08:00
25 lines
901 B
Python
25 lines
901 B
Python
from rest_framework import generics, viewsets
|
|
from .models import Subject
|
|
from .serializers import SubjectSerializer
|
|
from rest_framework.views import APIView
|
|
from rest_framework.response import Response
|
|
|
|
|
|
class SubjectListView(generics.ListAPIView):
|
|
serializer_class = SubjectSerializer
|
|
queryset = Subject.objects.all()
|
|
|
|
|
|
class SubjectByCourseYearSemesterView(generics.ListAPIView):
|
|
queryset = Subject.objects.all()
|
|
serializer_class = SubjectSerializer
|
|
|
|
def get(self, request, course_slug, year_slug, semester_slug):
|
|
# Retrieve the subjects based on year level and semester slugs
|
|
subjects = Subject.objects.filter(
|
|
courses__shortname=course_slug, year_levels__shortname=year_slug, semesters__shortname=semester_slug)
|
|
|
|
# Serialize the subjects
|
|
serializer = SubjectSerializer(subjects, many=True)
|
|
|
|
return Response(serializer.data)
|