Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hyperlinked UserDetailsSerializer #455

Open
mcferden opened this issue Aug 28, 2018 · 0 comments
Open

Hyperlinked UserDetailsSerializer #455

mcferden opened this issue Aug 28, 2018 · 0 comments

Comments

@mcferden
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant