I would like to change my postal code to ''
if its None
but cannot access the country_code parameter properly to do it. What am I doing wrong?
class AddressSchema(Schema):
def _postal_check(self, postal):
allowed_countries = ["GE","BT","HK","MO"]
postal_code = postal.postalCode
country_code = postal.countryCode
if postal_code is None and country_code in allowed_countries:
postal_code = ''
return postal_code
countryCode = fields.Str(validate=Length(equal=2), required=True)
postalCode = fields.Method(serialize='_postal_check', allow_none=True, required=True)
The problem was that I tried to access postal as an object and not as a dictionary so the solution is