From fd2563aff93756d8e6f1dc88b7e63336e083f989 Mon Sep 17 00:00:00 2001 From: Keannu Bernasol Date: Thu, 27 Jul 2023 00:43:31 +0800 Subject: [PATCH] Added some schema fields for drf-spectacular --- stude/accounts/serializers.py | 5 +++++ stude/study_groups/serializers.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/stude/accounts/serializers.py b/stude/accounts/serializers.py index 2d231bb..d2d8c13 100644 --- a/stude/accounts/serializers.py +++ b/stude/accounts/serializers.py @@ -14,6 +14,8 @@ from semesters.models import Semester from subjects.models import Subject from django.contrib.gis.geos import Point from django.utils.encoding import smart_str +from drf_spectacular.utils import extend_schema_field +from drf_spectacular.types import OpenApiTypes # There can be multiple subject instances with the same name, only differing in course, year level, and semester. We filter them here @@ -52,12 +54,15 @@ class CustomUserSerializer(BaseUserSerializer): read_only_fields = ('user_status', 'yearlevel_shortname', 'semester_shortname', 'course_shortname') + @extend_schema_field(OpenApiTypes.STR) def get_course_shortname(self, instance): return instance.course.shortname if instance.course else None + @extend_schema_field(OpenApiTypes.STR) def get_yearlevel_shortname(self, instance): return instance.year_level.shortname if instance.year_level else None + @extend_schema_field(OpenApiTypes.STR) def get_semester_shortname(self, instance): return instance.semester.shortname if instance.semester else None diff --git a/stude/study_groups/serializers.py b/stude/study_groups/serializers.py index d67fcb1..19cdec3 100644 --- a/stude/study_groups/serializers.py +++ b/stude/study_groups/serializers.py @@ -8,7 +8,7 @@ from landmarks.models import Landmark class StudyGroupSerializer(serializers.ModelSerializer): users = serializers.SlugRelatedField( - queryset=CustomUser.objects.all(), many=True, slug_field='name', required=False, allow_null=True) + queryset=CustomUser.objects.all(), many=True, slug_field='full_name', required=False, allow_null=True) subject = serializers.SlugRelatedField( many=False, slug_field='name', queryset=Subject.objects.all(), required=True, allow_null=False) location = PointField()