Anuj TBE
Anuj TBE

Reputation: 9800

Add extra fields to User Profile view in Django REST Framework

I'm using Django 2.x and Django REST Framework and Django REST Auth

By default, Django REST Auth provides an endpoint for Profile Details which returns details of authenticated user from the User model.

The default view provides fields

fields = ('pk', 'username', 'email', 'first_name', 'last_name')

and the endpoint is /api/user/

I want to add more fields to the serializer as I'm using a custom User model and have more fields added to it.

Do I need to create a Custom view and redefine the serializer class or I can extend the default provided view and serializer to add extra fields?

Upvotes: 0

Views: 880

Answers (1)

Davit Tovmasyan
Davit Tovmasyan

Reputation: 3588

If you check the docs you'll set that there is a configuration option for custom serializers. You can define your custom serializers for each endpoint without overriding urls and views by adding REST_AUTH_SERIALIZERS dictionary in your django settings.

Example:

REST_AUTH_SERIALIZERS = {
    'USER_DETAILS_SERIALIZER': 'path.to.custom.serializer' 
}

Upvotes: 2

Related Questions