diff --git a/stude/courses/admin.py b/stude/courses/admin.py index 41f0dbf..83c9d9a 100644 --- a/stude/courses/admin.py +++ b/stude/courses/admin.py @@ -1,5 +1,6 @@ from django.contrib import admin -from .models import Course +from .models import Course, SubjectCourse admin.site.register(Course) +admin.site.register(SubjectCourse) diff --git a/stude/subjects/admin.py b/stude/subjects/admin.py index 6014caa..a99cdc9 100644 --- a/stude/subjects/admin.py +++ b/stude/subjects/admin.py @@ -1,5 +1,10 @@ from django.contrib import admin +from courses.models import Course from .models import Subject -admin.site.register(Subject) +class SubjectAdmin(admin.ModelAdmin): + filter_horizontal = ['courses'] + + +admin.site.register(Subject, SubjectAdmin) diff --git a/stude/subjects/serializers.py b/stude/subjects/serializers.py index da21f6b..7669ffc 100644 --- a/stude/subjects/serializers.py +++ b/stude/subjects/serializers.py @@ -1,16 +1,20 @@ from rest_framework import serializers from .models import Subject +from courses.models import Course 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() + courses = serializers.SlugRelatedField( + queryset=Course.objects.all(), many=True, slug_field='name', allow_null=True) class Meta: model = Subject - fields = '__all__' + fields = ('name', 'code', 'courses', 'year_level', 'semester') def get_year_level(self, obj): return obj.year_level.name