mirror of
https://github.com/lemeow125/StudE-Backend.git
synced 2024-11-17 06:19:24 +08:00
Improved serializers
This commit is contained in:
parent
a67d8ae106
commit
288a1edd5e
2 changed files with 13 additions and 5 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue