[Answered ]-How to do user registration in Django REST framework api

2👍

Adding these other fields comes from manipulating the serializer. You could do something like this to expose those fields if you add field related_name='user_information' to your model definition:

user = models.OneToOneField(User, on_delete=models.CASCADE, related_name='user_information')

Then you create a serializer like:

class UserSerializer(serializers.HyperlinkedModelSerializer):

    phonenumber = serializers.CharField(source='user_information.phonenumber')
    address = serializers.CharField(source='user_information.address')

    class Meta:
        model = User

        fields = ('username', 'password', 'email', 'first_name', 'last_name',
            'phonenumber', 'address')

and instantiate that serializer in your view:

class UserViewSet(viewsets.ModelViewSet):
    queryset = User.objects.all()
    serializer_class = UserSerializer
    [...]

Leave a comment