2023-03-21 21:22:14 +08:00
|
|
|
from rest_framework import serializers
|
|
|
|
from django.contrib.auth.models import User
|
|
|
|
from .models import Subject
|
2023-04-11 23:20:01 +08:00
|
|
|
from students.models import Student
|
2023-03-21 21:22:14 +08:00
|
|
|
|
|
|
|
|
|
|
|
class SubjectSerializer(serializers.HyperlinkedModelSerializer):
|
2023-04-11 23:20:01 +08:00
|
|
|
students = serializers.SlugRelatedField(
|
2023-04-21 23:45:13 +08:00
|
|
|
queryset=Student.objects.all(), many=True, slug_field='last_name', allow_null=True)
|
2023-03-21 21:22:14 +08:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Subject
|
2023-04-11 23:20:01 +08:00
|
|
|
fields = ('id', 'name', 'students',
|
2023-03-21 21:59:09 +08:00
|
|
|
'max_slots', 'year_level', 'semester')
|
2023-03-21 21:50:54 +08:00
|
|
|
read_only_fields = ('id',)
|