From ac268cb4c86089ad64aad7c21365f887a214fcfc Mon Sep 17 00:00:00 2001 From: Keannu Bernasol Date: Tue, 4 Jul 2023 20:49:28 +0800 Subject: [PATCH] Improved custom user serializer --- stude/accounts/serializers.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/stude/accounts/serializers.py b/stude/accounts/serializers.py index ac5c23a..94518b1 100644 --- a/stude/accounts/serializers.py +++ b/stude/accounts/serializers.py @@ -13,11 +13,15 @@ from django.contrib.auth.password_validation import validate_password class CustomUserSerializer(BaseUserSerializer): user_status = StudentStatusSerializer( source='studentstatus', read_only=True) + course = serializers.StringRelatedField() + year_level = serializers.StringRelatedField() + semester = serializers.StringRelatedField() class Meta(BaseUserSerializer.Meta): model = CustomUser fields = ('username', 'email', 'student_id_number', 'year_level', 'semester', 'course', 'subjects', 'avatar', 'first_name', 'last_name', 'is_banned', 'user_status') + read_only_fields = ('is_banned', 'user_status') # The model from your custom user