Fix username in registration

This commit is contained in:
Keannu Bernasol 2024-01-18 13:38:12 +08:00
parent 7b511e0d8c
commit 83580f9aa5

View file

@ -21,6 +21,7 @@ class CustomUserSerializer(BaseUserSerializer):
class UserRegistrationSerializer(serializers.ModelSerializer): class UserRegistrationSerializer(serializers.ModelSerializer):
username = serializers.CharField(required=True)
email = serializers.EmailField(required=True) email = serializers.EmailField(required=True)
course = serializers.ChoiceField( course = serializers.ChoiceField(
choices=CustomUser.COURSE_CHOICES, allow_blank=True, allow_null=True) choices=CustomUser.COURSE_CHOICES, allow_blank=True, allow_null=True)
@ -32,7 +33,7 @@ class UserRegistrationSerializer(serializers.ModelSerializer):
model = CustomUser # Use your custom user model here model = CustomUser # Use your custom user model here
fields = ('username', 'email', 'password', 'course', 'section', fields = ('username', 'email', 'password', 'course', 'section',
'first_name', 'last_name') 'first_name', 'last_name')
read_only_fields = ('username', 'email', 'is_teacher', 'is_technician') read_only_fields = ('email', 'is_teacher', 'is_technician')
def validate(self, attrs): def validate(self, attrs):
user = self.Meta.model(**attrs) user = self.Meta.model(**attrs)