mirror of
https://github.com/lemeow125/StudE-Backend.git
synced 2024-11-17 06:19:24 +08:00
25 lines
936 B
Python
25 lines
936 B
Python
from rest_framework import serializers
|
|
from .models import Subject
|
|
from courses.models import Course
|
|
from year_levels.models import Year_Level
|
|
from semesters.models import Semester
|
|
from accounts.models import CustomUser
|
|
|
|
|
|
class SubjectSerializer(serializers.ModelSerializer):
|
|
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)
|
|
courses = serializers.SlugRelatedField(
|
|
queryset=Course.objects.all(), many=True, slug_field='name', allow_null=True)
|
|
|
|
class Meta:
|
|
model = Subject
|
|
fields = ('id', 'name', 'code', 'courses', 'year_levels', 'semesters')
|
|
|
|
def get_year_level(self, obj):
|
|
return obj.year_level.name
|
|
|
|
def get_semester(self, obj):
|
|
return obj.semester.name
|