Skip to content

Hyperlinked UserDetailsSerializer #455

Open
@mcferden

Description

@mcferden

I am trying to add a hyperlink to UserDetailsSerializer.
I wrote custom serializer like this:

class UserDetailsSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = User
        fields = ['id', 'url', 'username', 'email', 'first_name', 'last_name']

Registered it in settings.py:

REST_AUTH_SERIALIZERS = {
    'USER_DETAILS_SERIALIZER': 'user.serializers.UserDetailsSerializer',
}

When I am sending requests I am getting this error:

django.core.exceptions.ImproperlyConfigured: Could not resolve URL for hyperlinked relationship using view name "user-detail". You may have failed to include the related model in your API, or incorrectly configured the `lookup_field` attribute on this field.

I tried to set rest_user_details view name in serializer, but it didn't help.

class UserDetailsSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = User
        fields = ['id', 'url', 'username', 'email', 'first_name', 'last_name']
        extra_kwargs = {
            'url': {'view_name': 'rest_user_details'},
        }

Is there any way to make it work?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions