字段名称 | 作用 |
---|---|
read_only | 设置为True时,用于在序列化输出时使用该字段,但在反序列化创建或更新实例时不使用该字段。 |
write_only | 设置为True时,更新或创建实例时可以使用该字段,但在序列化输出时不显示该字段。 |
required | 设置为False,表示在反序列化更新和创建时,该字段不是必须的。 |
default | 反序列化时,为该字段设置一个默认值,同时包含关键字default和required是无效的,并且会引发错误。 |
allow_null | 设置为True时,表示序列化输出时,允许None作为有效值。 |
allow_blank | 设置为True时,表示在反序列化时,该字段的值可以为空。 |
class StudentUpdateSerializer(CustomModelSerializer):
"""
事件模型更新-序列化器
"""
class Meta:
model = Student
read_only_fields = ["id", "sid", 'name']
# exclude = ["page", "reserve", "modifier_name"]
exclude = ["page", "reserve"]
allow_blank = ["page", "reserve"]
# fields = "__all__"