Fixed serializer field for subject on ScheduleSerializer

This commit is contained in:
keannu125 2023-04-22 13:07:47 +08:00
parent 23a4a4a190
commit 864643278c

View file

@ -1,6 +1,7 @@
from rest_framework import serializers from rest_framework import serializers
from .models import Schedule from .models import Schedule
from professors.models import Professor from professors.models import Professor
from subjects.models import Subject
from students.models import Student from students.models import Student
@ -14,6 +15,9 @@ class ScheduleSerializer(serializers.HyperlinkedModelSerializer):
professor = serializers.SlugRelatedField( professor = serializers.SlugRelatedField(
queryset=Professor.objects.all(), slug_field='full_name', allow_null=True) queryset=Professor.objects.all(), slug_field='full_name', allow_null=True)
subject = serializers.SlugRelatedField(
queryset=Subject.objects.all(), slug_field='code', allow_null=True)
class Meta: class Meta:
model = Schedule model = Schedule
fields = ('id', 'subject', 'students_assigned', fields = ('id', 'subject', 'students_assigned',