Further polishing for subject

This commit is contained in:
Keannu Bernasol 2023-06-27 18:42:34 +08:00
parent 492a605557
commit c4bca9777c
3 changed files with 13 additions and 3 deletions

View file

@ -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)

View file

@ -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)

View file

@ -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