fix: base user phone校验可为空
This commit is contained in:
parent
059aee0acf
commit
1330b732c0
|
@ -255,7 +255,8 @@ class DeptCreateUpdateSerializer(CustomModelSerializer):
|
|||
"""
|
||||
部门序列化
|
||||
"""
|
||||
parent = serializers.PrimaryKeyRelatedField(queryset=Dept.objects.all(), required=True)
|
||||
parent = serializers.PrimaryKeyRelatedField(
|
||||
queryset=Dept.objects.all(), required=True)
|
||||
|
||||
class Meta:
|
||||
model = Dept
|
||||
|
@ -281,7 +282,9 @@ class UserSimpleSerializer(CustomModelSerializer):
|
|||
|
||||
|
||||
class UserSignatureSerializer(CustomModelSerializer):
|
||||
signature = serializers.CharField(source='employee.signature', read_only=True)
|
||||
signature = serializers.CharField(
|
||||
source='employee.signature', read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = User
|
||||
fields = ['id', 'username', 'name', 'phone', 'signature']
|
||||
|
@ -291,7 +294,8 @@ class UserListSerializer(CustomModelSerializer):
|
|||
"""
|
||||
用户列表序列化
|
||||
"""
|
||||
belong_dept_name = serializers.CharField(source='belong_dept.name', read_only=True)
|
||||
belong_dept_name = serializers.CharField(
|
||||
source='belong_dept.name', read_only=True)
|
||||
post_name = serializers.CharField(source='post.name', read_only=True)
|
||||
# posts_ = PostSimpleSerializer(source='posts', many=True)
|
||||
avatar_f = MyFilePathField(source='avatar', read_only=True)
|
||||
|
@ -302,7 +306,7 @@ class UserListSerializer(CustomModelSerializer):
|
|||
|
||||
|
||||
def phone_exist(phone):
|
||||
if User.objects.filter(phone=phone).exists():
|
||||
if phone and User.objects.filter(phone=phone).exists():
|
||||
raise serializers.ValidationError(**PHONE_EXIST)
|
||||
|
||||
|
||||
|
@ -316,7 +320,8 @@ class UserUpdateSerializer(CustomModelSerializer):
|
|||
"""
|
||||
用户编辑序列化
|
||||
"""
|
||||
phone = serializers.CharField(required=False)
|
||||
phone = serializers.CharField(
|
||||
required=False, allow_blank=True, allow_null=True)
|
||||
|
||||
class Meta:
|
||||
model = User
|
||||
|
@ -334,7 +339,8 @@ class UserCreateSerializer(CustomModelSerializer):
|
|||
创建用户序列化
|
||||
"""
|
||||
username = serializers.CharField(required=True, validators=[user_exist])
|
||||
phone = serializers.CharField(required=False, validators=[phone_exist])
|
||||
phone = serializers.CharField(required=False, validators=[
|
||||
phone_exist], allow_blank=True, allow_null=True)
|
||||
|
||||
class Meta:
|
||||
model = User
|
||||
|
@ -394,7 +400,8 @@ class UserInfoSerializer(CustomModelSerializer):
|
|||
|
||||
class Meta:
|
||||
model = User
|
||||
fields = ['id', 'username', 'name', 'post', 'avatar', 'belong_dept', 'type']
|
||||
fields = ['id', 'username', 'name', 'post',
|
||||
'avatar', 'belong_dept', 'type']
|
||||
|
||||
|
||||
class ApkSerializer(serializers.Serializer):
|
||||
|
|
Loading…
Reference in New Issue