marshmallow-peewee icon indicating copy to clipboard operation
marshmallow-peewee copied to clipboard

Object from Schema not full

Open fortunto2 opened this issue 6 years ago • 0 comments

Schema with custom full_path and url

class FileSchema(ModelSchema):

    storage = Related(required=True)
    mime = Related()
    user_id = fields.Int()
    user = Related(load_only=True)
    full_path = fields.FormattedString('{path}{name}')
    url = fields.FormattedString(S3_ENDPOINT_URL +'/{storage.bucket}/{path}{name}')

    class Meta:
        model = File

but, when load object

        fileSchema = FileSchema()
        file, errors = fileSchema.load(payload['file'])
        print(json.dumps(file.__dict__, indent=4, sort_keys=True, default=str))

i don't have file_path, only base File model fields


{
    "__data__": {
        "created_at": "2018-06-28 16:37:19",
        "hash": "Y9cR-xxxxxxxxx",
        "name": "vid20180619103313.mp4",
        "path": "xxxxxxxxxxxxx/",
        "size": null,
        "storage": null,
        "updated_at": "2018-06-28 16:37:19",
        "user": xxxxxx
    },
    "__rel__": {
        "storage": "None"
    },
    "_dirty": "{'user', 'created_at', 'path', 'name', 'storage', 'hash', 'size', 'updated_at'}",
    "url": "https://xxxxxxxxxxxxxx/vid20180619103313.mp4"
}

if dump


        result, errors = fileSchema.dump(file)
        print(type(result))
        print(json.dumps(result, indent=4, sort_keys=True))

all ok


{
    "created_at": "2018-06-28 16:37:19",
    "hash": "Y9cR-xxxxxxxxxxxx",
    "id": 7200,
    "mime_id": null,
    "name": "vid20180619103313.mp4",
    "path": "xxxxxxxxxxxxxxxx/",
    "size": null,
    "storage": {
        "bucket": "files",
        "id": 13,
        "type": "s3",
        "url": "xxxxxxxxxx/files"
    },
    "storage_id": 13,
    "updated_at": "2018-06-28 16:37:19",
    "url": "https://xxxxxxxxxxxxxxxxxxx/vid20180619103313.mp4",
    "user_id": xxxxxx
}


why not in object?

fortunto2 avatar Jun 30 '18 00:06 fortunto2