StudE-Backend/stude/subjects/serializers.py

22 lines
946 B
Python
Raw Permalink Normal View History

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