Skip to content
This repository was archived by the owner on Jun 6, 2024. It is now read-only.

Adding calculated attribute to the scheme #290

@Bu3a3a

Description

@Bu3a3a

Hi!
I'm trying to add a calculated field to the scheme using @post_dump:

from marshmallow_jsonapi import Schema as JSONApiSchema, fields


class MyScheme(JSONApiSchema):
    id = fields.Int(required=False)
    is_deleted = fields.Bool(required=True)
    is_enabled = fields.Bool(required=True)
    is_active = fields.Bool(required=False)

    class Meta:
        type_ = 'my_model'

    @post_dump
    def is_active(self, data):
        data['is_active'] = bool(not data['is_deleted'] and data['is_enabled'] ) 

I'm getting this error:

.../python3.7/site-packages/marshmallow_jsonapi/schema.py", line 355, in format_item
    attribute = attributes[field_name]
KeyError: 'is_active'

Is there a way to make it with marshmallow-jsonapi?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions