2023-06-27 18:15:31 +08:00
|
|
|
from rest_framework import serializers
|
2023-07-19 15:24:59 +08:00
|
|
|
from .models import Subject, SubjectCode
|
2023-06-27 18:42:34 +08:00
|
|
|
from courses.models import Course
|
2023-07-17 21:23:27 +08:00
|
|
|
from year_levels.models import Year_Level
|
|
|
|
from semesters.models import Semester
|
2023-07-18 15:51:06 +08:00
|
|
|
from accounts.models import CustomUser
|
2023-06-27 18:15:31 +08:00
|
|
|
|
|
|
|
|
|
|
|
class SubjectSerializer(serializers.ModelSerializer):
|
2023-07-17 21:23:27 +08:00
|
|
|
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)
|
2023-06-27 18:42:34 +08:00
|
|
|
courses = serializers.SlugRelatedField(
|
|
|
|
queryset=Course.objects.all(), many=True, slug_field='name', allow_null=True)
|
2023-07-19 15:24:59 +08:00
|
|
|
codes = serializers.SlugRelatedField(
|
|
|
|
queryset=SubjectCode.objects.all(), many=True, slug_field='code', allow_null=False)
|
2023-06-27 18:15:31 +08:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Subject
|
2023-07-19 15:36:06 +08:00
|
|
|
fields = ('id', 'name', 'codes', 'courses', 'year_levels', 'semesters')
|