mirror of
https://github.com/lemeow125/StudE-Backend.git
synced 2024-11-17 06:19:24 +08:00
Improved subject viewsets and subjects postmigration script
This commit is contained in:
parent
6af2bd0c0d
commit
8537b1d3ac
3 changed files with 19 additions and 2 deletions
|
@ -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']
|
||||
|
|
|
@ -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('<slug:course_slug>',
|
||||
SubjectByCourseView.as_view()),
|
||||
path('<slug:course_slug>/<slug:year_slug>/<slug:semester_slug>',
|
||||
SubjectByCourseYearSemesterView.as_view()),
|
||||
]
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue