2023-06-27 18:15:31 +08:00
|
|
|
from rest_framework import serializers
|
2023-09-03 17:46:36 +08:00
|
|
|
from .models import Subject, SubjectInstance
|
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-06-27 18:15:31 +08:00
|
|
|
|
|
|
|
|
|
|
|
class SubjectSerializer(serializers.ModelSerializer):
|
2023-09-03 17:46:36 +08:00
|
|
|
year_level = serializers.SlugRelatedField(
|
|
|
|
queryset=Subject.objects.all(), slug_field='name', allow_null=False)
|
2023-07-26 12:14:19 +08:00
|
|
|
year_level = serializers.SlugRelatedField(
|
|
|
|
queryset=Year_Level.objects.all(), slug_field='name', allow_null=True)
|
|
|
|
semester = serializers.SlugRelatedField(
|
|
|
|
queryset=Semester.objects.all(), slug_field='name', allow_null=True)
|
|
|
|
course = serializers.SlugRelatedField(
|
|
|
|
queryset=Course.objects.all(), slug_field='name', allow_null=True)
|
|
|
|
|
|
|
|
class Meta:
|
2023-09-03 17:46:36 +08:00
|
|
|
model = SubjectInstance
|
|
|
|
fields = ('id', 'subject', 'code', 'course', 'year_level', 'semester')
|