我必须重写序列化程序才能进行一些更改,但是在成功创建/注册后,我想自定义输出
序列化程序覆盖
class RegisterSerializer(UserCreatePasswordRetypeSerializer):
first_name = serializers.CharField(max_length=100)
last_name = serializers.CharField(max_length=100)
class Meta(UserCreatePasswordRetypeSerializer.Meta):
model = get_user_model()
# add extra fields to the "djoser" default fields
fields = UserCreatePasswordRetypeSerializer.Meta.fields + ("first_name", "last_name")
输出
{
"email": "test14@user.com",
"id": 17,
"first_name": "reni",
"last_name": "brake"
}
期望的输出
{
"data": {
"email": "test14@user.com",
"id": 17,
"first_name": "reni",
"last_name": "brake"
},
"success": True
}