-
-
Notifications
You must be signed in to change notification settings - Fork 640
Closed
Description
I have scheme like this:
class NullProcessingSchema(Schema):
@post_load
def null_to_default_value(self, data: dict, **kwargs):
return {
key: (0 if key == 'field_1' and value is None else value) # explicit field name
for key, value in data.items()
}
class ContentData(NullProcessingSchema):
field_1 = fields.Int(allow_none=True)
field_2 = fields.Str(allow_none=True)
# etc...
I have many fields with different types in ContentData
.
I don't want to explicitly list the field names in post_load
.
Is there a way to define a default value (when None) in the field itself?
Or is it possible to get the type of a field in post_load
?
zooozoo
Metadata
Metadata
Assignees
Labels
No labels