diff --git a/stude/subjects/models.py b/stude/subjects/models.py index d893e1a..c99d7b1 100644 --- a/stude/subjects/models.py +++ b/stude/subjects/models.py @@ -106,7 +106,7 @@ def populate_subjects(sender, **kwargs): subject_year_level = year_term[0].strip() subject_semester = year_term[1].strip() subject_code = row[1] - subject_name = row[2] + subject_name = row[2].replace("\n", " ") # Definitions of subjects to ignore ignored_subject_codes = ['NSTP', 'ROTC', 'CWTS', 'LTS'] diff --git a/stude/subjects/urls.py b/stude/subjects/urls.py index 587c879..b1c131f 100644 --- a/stude/subjects/urls.py +++ b/stude/subjects/urls.py @@ -1,8 +1,10 @@ from django.urls import include, path -from .views import SubjectByCourseYearSemesterView, SubjectListView +from .views import SubjectByCourseView, SubjectByCourseYearSemesterView, SubjectListView from rest_framework import routers urlpatterns = [ path('', SubjectListView.as_view()), + path('', + SubjectByCourseView.as_view()), path('//', SubjectByCourseYearSemesterView.as_view()), ] diff --git a/stude/subjects/views.py b/stude/subjects/views.py index df043c7..6e3286f 100644 --- a/stude/subjects/views.py +++ b/stude/subjects/views.py @@ -10,6 +10,21 @@ class SubjectListView(generics.ListAPIView): queryset = Subject.objects.all() +class SubjectByCourseView(generics.ListAPIView): + queryset = Subject.objects.all() + serializer_class = SubjectSerializer + + def get(self, request, course_slug): + # Retrieve the subjects based on year level and semester slugs + subjects = Subject.objects.filter( + courses__shortname=course_slug).order_by('-subjectyearlevel') + + # Serialize the subjects + serializer = SubjectSerializer(subjects, many=True) + + return Response(serializer.data) + + class SubjectByCourseYearSemesterView(generics.ListAPIView): queryset = Subject.objects.all() serializer_class = SubjectSerializer