mirror of
https://github.com/lemeow125/StudE-Backend.git
synced 2024-11-17 06:19:24 +08:00
Added some schema fields for drf-spectacular
This commit is contained in:
parent
a608db275c
commit
fd2563aff9
2 changed files with 6 additions and 1 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue