diff --git a/stude/subjects/migrations/0004_rename_courses_subject_course.py b/stude/subjects/migrations/0004_rename_courses_subject_course.py new file mode 100644 index 0000000..61e8482 --- /dev/null +++ b/stude/subjects/migrations/0004_rename_courses_subject_course.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.3 on 2023-07-17 12:43 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('subjects', '0003_remove_subject_semester_remove_subject_year_level_and_more'), + ] + + operations = [ + migrations.RenameField( + model_name='subject', + old_name='courses', + new_name='course', + ), + ] diff --git a/stude/subjects/migrations/0005_rename_course_subject_courses.py b/stude/subjects/migrations/0005_rename_course_subject_courses.py new file mode 100644 index 0000000..eb87ae8 --- /dev/null +++ b/stude/subjects/migrations/0005_rename_course_subject_courses.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.3 on 2023-07-17 13:11 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('subjects', '0004_rename_courses_subject_course'), + ] + + operations = [ + migrations.RenameField( + model_name='subject', + old_name='course', + new_name='courses', + ), + ] diff --git a/stude/subjects/migrations/0006_rename_semester_subject_semesters_and_more.py b/stude/subjects/migrations/0006_rename_semester_subject_semesters_and_more.py new file mode 100644 index 0000000..97ce344 --- /dev/null +++ b/stude/subjects/migrations/0006_rename_semester_subject_semesters_and_more.py @@ -0,0 +1,23 @@ +# Generated by Django 4.2.3 on 2023-07-17 13:16 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('subjects', '0005_rename_course_subject_courses'), + ] + + operations = [ + migrations.RenameField( + model_name='subject', + old_name='semester', + new_name='semesters', + ), + migrations.RenameField( + model_name='subject', + old_name='year_level', + new_name='year_levels', + ), + ] diff --git a/stude/subjects/models.py b/stude/subjects/models.py index 7b9f611..bf00019 100644 --- a/stude/subjects/models.py +++ b/stude/subjects/models.py @@ -12,10 +12,10 @@ class Subject(models.Model): students = models.ManyToManyField( 'accounts.CustomUser', through='subjects.SubjectStudent', related_name='SubjectStudent_subject') - year_level = models.ManyToManyField( + year_levels = models.ManyToManyField( 'year_levels.Year_Level', through='subjects.SubjectYearLevel', related_name='SubjectYearLevel_subject') - semester = models.ManyToManyField( + semesters = models.ManyToManyField( 'semesters.Semester', through='subjects.SubjectSemester', related_name='SubjectSemester_subject') def __str__(self): diff --git a/stude/subjects/serializers.py b/stude/subjects/serializers.py index 7669ffc..aa064a8 100644 --- a/stude/subjects/serializers.py +++ b/stude/subjects/serializers.py @@ -1,20 +1,24 @@ from rest_framework import serializers from .models import Subject from courses.models import Course +from year_levels.models import Year_Level +from semesters.models import Semester from year_levels.serializers import YearLevelSerializer from semesters.serializers import SemesterSerializer from courses.serializers import CourseSerializer class SubjectSerializer(serializers.ModelSerializer): - year_level = serializers.SerializerMethodField() - semester = serializers.SerializerMethodField() + year_levels = serializers.SlugRelatedField( + queryset=Year_Level.objects.all(), many=True, slug_field='name', allow_null=True) + semesters = serializers.SlugRelatedField( + queryset=Semester.objects.all(), many=True, slug_field='name', allow_null=True) courses = serializers.SlugRelatedField( queryset=Course.objects.all(), many=True, slug_field='name', allow_null=True) class Meta: model = Subject - fields = ('name', 'code', 'courses', 'year_level', 'semester') + fields = ('name', 'code', 'courses', 'year_levels', 'semesters') def get_year_level(self, obj): return obj.year_level.name diff --git a/stude/subjects/urls.py b/stude/subjects/urls.py index 5d3c133..6c0d533 100644 --- a/stude/subjects/urls.py +++ b/stude/subjects/urls.py @@ -1,11 +1,9 @@ from django.urls import include, path from .views import SubjectListView -from .views import SubjectByYearSemesterView, SubjectByYearView +from .views import SubjectByYearSemesterView urlpatterns = [ path('', SubjectListView.as_view()), - path('/', - SubjectByYearView.as_view()), - path('/', + path('//', SubjectByYearSemesterView.as_view()), ] diff --git a/stude/subjects/views.py b/stude/subjects/views.py index 9842658..bdcec22 100644 --- a/stude/subjects/views.py +++ b/stude/subjects/views.py @@ -10,27 +10,13 @@ class SubjectListView(generics.ListAPIView): queryset = Subject.objects.all() -class SubjectByYearView(generics.ListAPIView): - queryset = Subject.objects.all() - - def get(self, request, year_slug): - # Retrieve the subjects based on year level and semester slugs - subjects = Subject.objects.filter( - year_level__shortname=year_slug) - - # Serialize the subjects - serializer = SubjectSerializer(subjects, many=True) - - return Response(serializer.data) - - class SubjectByYearSemesterView(generics.ListAPIView): queryset = Subject.objects.all() - def get(self, request, year_slug, semester_slug): + def get(self, request, course_slug, year_slug, semester_slug): # Retrieve the subjects based on year level and semester slugs subjects = Subject.objects.filter( - year_level__shortname=year_slug, semester__shortname=semester_slug) + courses__shortname=course_slug, year_levels__shortname=year_slug, semesters__shortname=semester_slug) # Serialize the subjects serializer = SubjectSerializer(subjects, many=True)