Improved serializers

This commit is contained in:
Keannu Bernasol 2023-07-06 21:47:28 +08:00
parent a67d8ae106
commit 288a1edd5e
2 changed files with 13 additions and 5 deletions

View file

@ -8,14 +8,20 @@ from student_status.serializers import StudentStatusSerializer
from student_status.models import StudentStatus
from rest_framework.settings import api_settings
from django.contrib.auth.password_validation import validate_password
from courses.models import Course
from year_levels.models import Year_Level
from semesters.models import Semester
class CustomUserSerializer(BaseUserSerializer):
user_status = StudentStatusSerializer(
source='studentstatus', read_only=True)
course = serializers.StringRelatedField()
year_level = serializers.StringRelatedField()
semester = serializers.StringRelatedField()
course = serializers.SlugRelatedField(
many=False, slug_field='name', queryset=Course.objects.all(), required=False, allow_null=True)
year_level = serializers.SlugRelatedField(
many=False, slug_field='name', queryset=Year_Level.objects.all(), required=False, allow_null=True)
semester = serializers.SlugRelatedField(
many=False, slug_field='name', queryset=Semester.objects.all(), required=False, allow_null=True)
class Meta(BaseUserSerializer.Meta):
model = CustomUser

View file

@ -1,12 +1,14 @@
from rest_framework import serializers
from .models import StudyGroup, StudyGroupMembership
from accounts.models import CustomUser
from subjects.models import Subject
class StudyGroupSerializer(serializers.ModelSerializer):
users = serializers.SlugRelatedField(
queryset=CustomUser.objects.all(), many=True, slug_field='name', allow_null=True)
subject = serializers.CharField(source='subject.Subject', read_only=True)
queryset=CustomUser.objects.all(), many=True, slug_field='name', required=False, allow_null=True)
subject = serializers.SlugRelatedField(
many=False, slug_field='name', queryset=Subject.objects.all(), required=True, allow_null=False)
class Meta:
model = StudyGroup