Here is the serilializer causing the issue. There is a problem with the create function where the validated data cannot process first_name
because it is not validated at the top, but I don’t want it to have a unique validation, so what do I do?
class SignUpSerializer(serializers.Serializer):
username = serializers.CharField(
required = True,
validators = [UniqueValidator(queryset=User.objects.all())]
)
email = serializers.CharField(
required = True,
validators = [UniqueValidator(queryset=User.objects.all())]
)
password = serializers.CharField(write_only = True,required = True,validators=[validate_password])
password_confirmation = serializers.CharField(write_only = True,required = True)
class Meta:
model = User
fields = ['username', 'first_name', 'last_name', 'email', 'bio', 'preferences', 'password', 'password_confirmation']
extra_kwargs = {
'first_name': {'required': True},
'last_name': {'required': True},
'preferences': {'required': True}
}
def validate(self,data):
if data['password'] != data['password_confirmation']:
raise serializers.ValidationError({"password": "Passwords don't match."})
return data
def create(self,validated_data):
user = User.objects.create(
username = validated_data['username'],
first_name = validated_data['first_name'],
last_name = validated_data['last_name'],
email = validated_data['email'],
bio = validated_data['bio'],
preferences = validated_data['preferences']
)
user.set_password(validated_data['password'])
user.save()
return user