1👍
✅
Finally I inherited from UserCreatePasswordRetypeSerializer instead of UserCreateSerializer to have both re_password field and my customized serializer.
And also I deleted "USER_CREATE_PASSWORD_RETYPE": True
from settings and it works properly.
0👍
There is no need to remove "USER_CREATE_PASSWORD_RETYPE": True
from settings.py. You simply need to define new serializer
from djoser.serializers import UserCreatePasswordRetypeSerializer
class CustomUserCreatePasswordRetypeSerializer(UserCreatePasswordRetypeSerializer):
class Meta(UserCreatePasswordRetypeSerializer.Meta):
fields = ['id', 'username', 'password', 'email', 'first_name', 'last_name']
and in settings.py
DJOSER = {
"SERIALIZERS": {
'user_create_password_retype': 'core.serializers.CustomUserCreatePasswordRetypeSerializer',
}
}
as it uses user_create_password_retype
serializer when "USER_CREATE_PASSWORD_RETYPE"
is set to True
.
- [Answered ]-How to display value of a field in a *linked* table, in a Django template?
- [Answered ]-Django – JSON Serialization error
- [Answered ]-Unable to filter using django-filters
- [Answered ]-Configuring multi-tenancy
- [Answered ]-Django admin site
0👍
from djoser.serializers import UserCreatePasswordRetypeSerializer
class CustomUserCreatePasswordRetypeSerializer(UserCreatePasswordRetypeSerializer):
class Meta(UserCreatePasswordRetypeSerializer.Meta):
fields = ['id', 'username', 'email', 'first_name', 'last_name', 'password']
DJOSER = {
'PASSWORD_RESET_CONFIRM_URL': '#/password/reset/confirm/{uid}/{token}',
'USERNAME_RESET_CONFIRM_URL': '#/username/reset/confirm/{uid}/{token}',
'ACTIVATION_URL': '#/activate/{uid}/{token}',
'SEND_ACTIVATION_EMAIL': True,
'USER_CREATE_PASSWORD_RETYPE': True,
'SERIALIZERS': {
'user_create': 'core.serializers.UserCreateSerializer',
'current_user': 'core.serializers.UserSerializer',
'user_create_password_retype': 'core.serializers.CustomUserCreatePasswordRetypeSerializer',
},
}
- [Answered ]-Django send mail and sms after 6 hours of user sign up
- [Answered ]-PUT method not working in django-tastypie?
- [Answered ]-Using class-based UpdateView on a m-t-m with an intermediary model
- [Answered ]-Why the User data are not updated? in Django?
0👍
This is worked for me:
Settings Djoser:
"SERIALIZERS":{
'user_create':'account.serializers.CustomUserCreateSerializer',
'user':'account.serializers.CustomUserCreateSerializer',
'user_delete': 'djoser.serializers.UserDeleteSerializer',
'user_create_password_retype': 'account.serializers.CustomUserCreateSerializer',
'password_reset': 'account.serializers.PasswordResetEmailSentSerializer',
},
Custom Serializer:
from djoser.serializers import SendEmailResetSerializer, UserCreatePasswordRetypeSerializer
from rest_framework import serializers
from account.models import CustomUser
class CustomUserCreateSerializer(UserCreatePasswordRetypeSerializer):
class Meta(UserCreatePasswordRetypeSerializer.Meta):
model = CustomUser
fields =('id','first_name','last_name','email','phone_number','password',)
Source:stackexchange.com