[Fixed]-Customize the djoser create user endpoint

12👍

Having in mind that you have set the AUTH_USER_MODEL to your User model.

Just import the Djoser User Registration Serializer And override it.

from djoser.serializers import UserCreateSerializer as BaseUserRegistrationSerializer

class UserRegistrationSerializer(BaseUserRegistrationSerializer):
    class Meta(BaseUserRegistrationSerializer.Meta):
        fields = ('url', 'id', 'email', 'name', 'last_name', 'account_address', 'password', )

You can also override other things in the serializer like create and update methods in case if you want to customize it.

And in settings.py

DJOSER = {
    ...
    'SERIALIZERS': {
         'user_create': 'yourapp.serializer.UserRegistrationSerializer'
    }
    ...
}

4👍

For me, I wanted to write a custom create method and it worked when I override user_create_password_retype and used mine since this is internally using the UserCreateSerializer from djoser

DJOSER = {
      ...
    "SERIALIZERS": {
        "user_create": "account.serializers.user_serializer.CustomUserCreateSerializer",
        "user": "account.serializers.user_serializer.CustomUserSerializer",
        "user_create_password_retype": "account.serializers.user_serializer.UserCreatePasswordRetypeSerializer",
    }
      ...
}

Other settings –
AUTH_USER_MODEL to your custom User model.

Leave a comment