Skip to content
本页目录

继承了CustomModelSerializer和CustomModelViewSet系统会自动处理权限关系

CustomModelSerializer自定义序列化

在create创建时会判断modifier(修改人字段)、creator(创建者字段)、dept_belong_id(数据归属字段)是否存在提交的序列化中。如果存在就会自动填充当前字段为修改、创建的人id。

注意:fields = "__all__" 时才会包含modifier(修改人字段)、creator(创建者字段)、dept_belong_id(数据归属字段)字段。如果这三个字段被排除或者fields没有包含则无法自动创建数据部门归属等。

class OtherManageSerializer(CustomModelSerializer):
    """
    其他设置 简单序列化器
    """

    class Meta:
        model = OtherManage
        fields = "__all__"
        # exclude=['dept_belong_id','modifier','creator','description']
        read_only_fields = ["id"]

Released under the Apache License 2.0