2023-04-22 11:00:04 +08:00
|
|
|
from rest_framework import serializers
|
|
|
|
from .models import Schedule
|
2023-04-22 11:59:16 +08:00
|
|
|
from professors.models import Professor
|
2023-04-22 13:07:47 +08:00
|
|
|
from subjects.models import Subject
|
2023-04-22 14:38:27 +08:00
|
|
|
from daytimes.models import DayTime
|
2023-04-22 11:59:16 +08:00
|
|
|
from students.models import Student
|
2023-04-22 11:00:04 +08:00
|
|
|
|
|
|
|
|
|
|
|
class ScheduleSerializer(serializers.HyperlinkedModelSerializer):
|
|
|
|
date_created = serializers.DateTimeField(
|
|
|
|
format="%d-%m-%Y %I:%M%p", read_only=True)
|
|
|
|
|
2023-04-22 14:38:27 +08:00
|
|
|
students_assigned = serializers.SlugRelatedField(
|
|
|
|
queryset=Student.objects.all(), many=True, slug_field='full_name', allow_null=True)
|
2023-04-22 11:59:16 +08:00
|
|
|
|
|
|
|
professor = serializers.SlugRelatedField(
|
|
|
|
queryset=Professor.objects.all(), slug_field='full_name', allow_null=True)
|
|
|
|
|
2023-04-22 13:07:47 +08:00
|
|
|
subject = serializers.SlugRelatedField(
|
|
|
|
queryset=Subject.objects.all(), slug_field='code', allow_null=True)
|
|
|
|
|
2023-04-22 14:38:27 +08:00
|
|
|
daytimes = serializers.SlugRelatedField(
|
|
|
|
queryset=DayTime.objects.all(), slug_field='name', allow_null=True)
|
|
|
|
|
2023-04-22 11:00:04 +08:00
|
|
|
class Meta:
|
|
|
|
model = Schedule
|
2023-04-22 14:38:27 +08:00
|
|
|
fields = ('id', 'name', 'subject', 'daytimes', 'students_assigned',
|
2023-04-22 11:00:04 +08:00
|
|
|
'professor', 'date_created')
|
2023-04-22 14:14:53 +08:00
|
|
|
read_only_fields = ('id', 'date_created', 'name')
|