Improved subject viewset

This commit is contained in:
Keannu Bernasol 2023-07-25 17:03:05 +08:00
parent 8537b1d3ac
commit 83b817ec35

View file

@ -17,7 +17,7 @@ class SubjectByCourseView(generics.ListAPIView):
def get(self, request, course_slug): def get(self, request, course_slug):
# Retrieve the subjects based on year level and semester slugs # Retrieve the subjects based on year level and semester slugs
subjects = Subject.objects.filter( subjects = Subject.objects.filter(
courses__shortname=course_slug).order_by('-subjectyearlevel') courses__shortname=course_slug).distinct()
# Serialize the subjects # Serialize the subjects
serializer = SubjectSerializer(subjects, many=True) serializer = SubjectSerializer(subjects, many=True)
@ -32,7 +32,7 @@ class SubjectByCourseYearSemesterView(generics.ListAPIView):
def get(self, request, course_slug, year_slug, semester_slug): def get(self, request, course_slug, year_slug, semester_slug):
# Retrieve the subjects based on year level and semester slugs # Retrieve the subjects based on year level and semester slugs
subjects = Subject.objects.filter( subjects = Subject.objects.filter(
courses__shortname=course_slug, year_levels__shortname=year_slug, semesters__shortname=semester_slug) courses__shortname=course_slug, year_levels__shortname=year_slug, semesters__shortname=semester_slug).distinct()
# Serialize the subjects # Serialize the subjects
serializer = SubjectSerializer(subjects, many=True) serializer = SubjectSerializer(subjects, many=True)