1

I'm trying to override the RegisterSerializer to add additional field that i could save on the backend while the signup process but i couldn't get it to work. I'm using React as a view layer and it passes the data perfectly when i use the default RegisterSerializer after adding RegisterSerializerCustom it doesn't work at all

here is my code :

    from rest_auth.registration.serializers import RegisterSerializer
    class RegisterSerializerCustom(RegisterSerializer):
        mobile = serializers.CharField(required=False, write_only=True)

        def get_cleaned_data(self):
            return {
                'username': self.validated_data.get('username', ''),
                'password1': self.validated_data.get('password1', ''),
                'email': self.validated_data.get('email', ''),
                'mobile': self.validated_data.get('mobile', ''),
            }

        def validate_mobile(self, mobile):
            return mobile

        def save(self, request):
            res = super(RegisterSerializerCustom, serializers).save(request)
            return res

and i added my these in setting.py

REST_AUTH_SERIALIZERS = {
'REGISTER_SERIALIZER':'user_profile.serializers.RegisterSerializerCustom',
}

what is the problem in my code ?!

  • You say it doesn't work at all - is there an error? What happens? – Will Keeling Mar 26 '18 at 12:27
  • it doesn't run at all , like if it's not there , i found another path to do what i want but this issue is strange and i don't know what i did wrong –  Mar 26 '18 at 12:37
  • Please check out this thread, I think this is exactly your problem: https://stackoverflow.com/questions/37841612/django-rest-auth-custom-registration-fails-to-save-extra-fields – mariodev Apr 07 '18 at 15:30

1 Answers1

2

It must be registered in setting.py like this:

REST_AUTH_REGISTER_SERIALIZERS = {
   'REGISTER_SERIALIZER':'user_profile.serializers.RegisterSerializerCustom',
}
peter
  • 1,482
  • 4
  • 16
  • 38