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 student_status.models import StudentStatus
|
||||||
from rest_framework.settings import api_settings
|
from rest_framework.settings import api_settings
|
||||||
from django.contrib.auth.password_validation import validate_password
|
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):
|
class CustomUserSerializer(BaseUserSerializer):
|
||||||
user_status = StudentStatusSerializer(
|
user_status = StudentStatusSerializer(
|
||||||
source='studentstatus', read_only=True)
|
source='studentstatus', read_only=True)
|
||||||
course = serializers.StringRelatedField()
|
course = serializers.SlugRelatedField(
|
||||||
year_level = serializers.StringRelatedField()
|
many=False, slug_field='name', queryset=Course.objects.all(), required=False, allow_null=True)
|
||||||
semester = serializers.StringRelatedField()
|
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):
|
class Meta(BaseUserSerializer.Meta):
|
||||||
model = CustomUser
|
model = CustomUser
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
from .models import StudyGroup, StudyGroupMembership
|
from .models import StudyGroup, StudyGroupMembership
|
||||||
from accounts.models import CustomUser
|
from accounts.models import CustomUser
|
||||||
|
from subjects.models import Subject
|
||||||
|
|
||||||
|
|
||||||
class StudyGroupSerializer(serializers.ModelSerializer):
|
class StudyGroupSerializer(serializers.ModelSerializer):
|
||||||
users = serializers.SlugRelatedField(
|
users = serializers.SlugRelatedField(
|
||||||
queryset=CustomUser.objects.all(), many=True, slug_field='name', allow_null=True)
|
queryset=CustomUser.objects.all(), many=True, slug_field='name', required=False, allow_null=True)
|
||||||
subject = serializers.CharField(source='subject.Subject', read_only=True)
|
subject = serializers.SlugRelatedField(
|
||||||
|
many=False, slug_field='name', queryset=Subject.objects.all(), required=True, allow_null=False)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = StudyGroup
|
model = StudyGroup
|
||||||
|
|
Loading…
Reference in a new issue