class AccountSerializer(serializers.ModelSerializer): class Meta: # 模型名称 model = User # 序列化返回的字段 fields = ('id', 'account_name', 'users', 'created') # 这个字段不返回 exclude = ('users',) # 显示的深度 depth = 1 # 默认只读,不接受用户修改 跟字段设置的read_only=True效果一样 read_only_fields = ('account_name',)